Hash table and linked list implementation of the Map interface,with predictable iteration order. This implementation differs from HashMap in that it maintains a doubly-linked list running through all of its entries.
LinkedHashMap实现了Map接口,继承于HashMap,与HashMap不同的是它维持有一个双链表,从而可以保证迭代时候的顺序。
public class TestLinkedHashMap {
public static void main(String[] args) {
Map<String,String> map = new LinkedHashMap<String,String>();
map.put("数学","数学老师");
map.put("化学","化学老师");
map.put("物理","物理老师");
map.put("生物","生物老师");
map.put("政治","政治老师");
for(Entry<String, String> entry : map.entrySet()) {
System.out.println(entry.getKey() + "-->" + entry.getValue());
}
}
}