entrySet()
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
public class map{
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<String>();
HashMap<Object,Object> hash = new HashMap<Object,Object>();
TreeMap<Object,Object> treeMap = new TreeMap<Object,Object>();
list.add("a");
list.add("b");
list.add("c");
hash.put(3, 312);
hash.put(4, 412);
hash.put(5, 512);
hash.put(6, 612);
hash.put(1, 112);
hash.put(2, 212);
treeMap.put(3, 33);
treeMap.put(1, 11);
treeMap.put(2, 22);
treeMap.put(4, 44);
treeMap.put(5, 55);
treeMap.put(6, 66);
//list遍历
for(String m: list){
System.out.println(m);
}
// hashmap entrySet() 遍历
for(Map.Entry<Object,Object> m: hash.entrySet()){
System.out.println(m.getKey()+"+++"+m.getValue());
}
//hashmap keySet() 遍历
for(Object m: hash.keySet()){
System.out.println(m+"---"+hash.get(m));
}
// treemap keySet()遍历
for(Object m: treeMap.keySet()){
System.out.println(m+"***"+treeMap.get(m));
}
}
原文出处:http://wangqiaowqo.iteye.com/blog/1169512
}