Map集合

创建一个Map集合

集合的Key都是String类型

集合的Value是Object类型

HashMap<String Object> map = new HashMap<>();

//向Map集合中增加数据

map.put("小狗","dog");

map.put("小猫","cat");

map.put("桌子","desk");

//从Map集合中获取指定的元素,根据key获取对应的value值

System.out.println("dog对应的value值是===》"+map.get("dog"));

Set<Entry<String ,Object>> entrySet  = map.entrySet();

Iterator<Entry<String,Object>> iterator = entry.iterator();

while(iterator.hasNext()){

          Entry<String,Object> entry = iterator.next();

          System.out.println(entry.getKey()+"====》"+entry.getValue());

}

原文地址:https://www.cnblogs.com/liutianci/p/8087009.html