java 按顺序存取的map linkedhashmap

1.hashmap

Map map=new HashMap();
map.put("adfa", "1");
map.put("bacaa", "2");
map.put("ceewq", "3");
map.put("dklo", "4");
for(String key:map.keySet())
	System.out.println(key+"==>"+map.get(key));
adfa==>1
dklo==>4
bacaa==>2
ceewq==>3

2.linkedhashmap

Map map=new LinkedHashMap();
map.put("adfa", "1");
map.put("bacaa", "2");
map.put("ceewq", "3");
map.put("dklo", "4");
for(String key:map.keySet())
	System.out.println(key+"==>"+map.get(key));
adfa==>1
bacaa==>2
ceewq==>3
dklo==>4

 

你可能感兴趣的:(java)