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());

}

 

posted on 2017-12-22 17:26  天天xiangshang  阅读(133)  评论(0编辑  收藏  举报

导航