--LinkedHashMap是HashMap的一個子類接口
--HashMap和LinkedHashMap都是實現Map接口get
--區別在於HashMap並非按插入次序順序存放的,而LinkedHashMap是按照插入順序存放的.map
例:static
public static void main(String[] args) {
Map<String,String> hmap = new HashMap<String,String>();
Map<String,String> lmap = new LinkedHashMap<String,String>();
for (int i = 0; i < 15; i++) {
hmap.put(""+i, ""+i);
lmap.put(""+i, ""+i);
}
System.out.println("HashMap:");
for (Entry<String,String> e : hmap.entrySet()) {
System.out.print(e.getValue());
}
System.out.println("");
System.out.println("LinkedHashMap:");
for (Entry<String,String> e : lmap.entrySet()) {
System.out.print(e.getValue());
}
}
輸出結果new
HashMap:
11121314012345678910
LinkedHashMap:
01234567891011121314void