import java.util.*;
public class HelloWorld {
public static void main(String []args) {
Map<Integer,String> map = new HashMap<Integer,String>();
map.put(1,"zhangshan1");
map.put(2,"zhangshan2");
map.put(3,"zhangshan3");
map.put(4,"zhangshan4");
System.out.println("value="+map.containsKey(2));
System.out.println("key="+map.containsValue("zhangshan1"));
map.put(null,"ceshi");
System.out.println(map.get(null));
Collection<String> coll=map.values();
System.out.println(coll);
System.out.println(map.remove(null));
Set<Integer> keyset = map.keySet();
Iterator<Integer> it = keyset.iterator();
while(it.hasNext()){
Integer i =it.next();
String s = map.get(i);
System.out.println("[K:"+i+"="+"V:"+s+"]");
}
}
} |
|