- 保存形式:key——>value的方式保存
- 常用子类:
HashMap:无序,key不允许重复
TreeMap:有序,key不允许重复
public static void main(String args[]){
Map<String,String> map = new HashMap<String,String>();
map.put<"key1","www">;
map.put<"key2","wmathor">;
map.put<"key3","com">;
String str = map.get("key1");
System.out.println(str);//www
if(map.containsKey("key2"){
System.out.println("key2存在");
}
if(map.containsValue("wmathor"){
System.out.println("wmathor存在");
}
Set<String> s = map.keySet();
Iterator<String> it = s.iterator();
while(it.hasNext()){
System.out.println(it.next());
}
Collection<String> c = map.values();
Iterator<String> i = c.iterator();
while(i.hasNext()){
System.out.println(it.next());
}
}