Map

2018-06-06 14:15:16 浏览数 (2)

  1. 保存形式:key——>value的方式保存
  2. 常用子类: HashMap:无序,key不允许重复

HashTable:无序,key不允许重复

代码语言:javascript复制
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.hashNext()){
        System.out.println(it.next());
    }
    
    Collection<String> c = map.values();
    Iterator<String> i = c.iterator();
    while(i.hashNext()){
        System.out.println(it.next());
    }
}

0 人点赞