import java.util.*;
public class MainClass {
public static void main(String args[])
{
String[] sa={"mary","tom"};
Hashtable<String,Integer> ht=new Hashtable<String,Integer>();//
for(int i=0;i<sa.length;i++)
ht.put(sa[i], new Integer(i));
//往哈希表中添加元素,并使得关键字与值之间建立起映射关系
System.out.println(ht.get("mary"));
}
}
|
|