Map 遍历
使用EntrySet和Entry
Map<String,String> map=new HashMap<String,String>(); map.put("A", "a"); map.put("B", "b"); map.put("C", "c"); Set set=map.entrySet(); for (Object object : set) { Entry entry=(Entry)object; System.out.println(entry.getKey()+":"+entry.getValue()); }
使用迭代器Iterator
Map map=new HashMap(); map.put("A", "a"); map.put("B", "b"); map.put("C", "c"); Set set=map.keySet(); Iterator it=set.iterator(); Object key; Object value; while(it.hasNext()){ key=it.next(); value=map.get(key); System.out.println(key+":"+value); }