Map集合的遍历1-键找值 (Iterator 遍历)
Map map = new HashMap(); map.put("a","java"); map.put("b","c++"); map.put("c","php"); map.put("d","python"); map.put("e","erlang"); Set set = map.keySet(); Iterator it = set.iterator(); while (it.hasNext()){ String key = it.next(); String values = map.get(key); System.out.println(key+"=="+values); }
Map集合的遍历2-键值对映射关系(Iterator 遍历)
Map map = new HashMap(); map.put("a","java"); map.put("b","c++"); map.put("c","php"); map.put("d","python"); map.put("e","erlang"); Set> set = map.entrySet(); Iterator> it = set.iterator(); while (it.hasNext()){ Map.Entry entry = it.next(); String key = entry.getKey(); String value = entry.getValue(); System.out.println(key+"=="+value); }
Map集合的遍历3-键找值(for遍历)
Map map = new HashMap(); map.put("a","java"); map.put("b","c++"); map.put("c","php"); map.put("d","python"); map.put("e","erlang"); for(String key :map.keySet()){ System.out.println(key+"=="+map.get(key)); }
Map集合的遍历4-键值对映射关系(for遍历)
Map map = new HashMap(); map.put("a","java"); map.put("b","c++"); map.put("c","php"); map.put("d","python"); map.put("e","erlang"); for(Map.Entry entry:map.entrySet()){ System.out.println(entry.getKey()+"=="+entry.getValue()); }