LinkedHashMap是Map接口的实现类,key以LinkedHashSet存储。
哈希表散列Key,链表维持Key的添加顺序。
LinkedHashMap的添加和遍历:
1 public class Demo1 { 2 3 public static void main(String[] args) { 4 /*HashMapmap=new HashMap (); 5 Student student=new Student(1,"大明",20); 6 Student student1=new Student(1,"大明",20); 7 Student student2=new Student(3,"舔狗",22); 8 9 ArrayList list=new ArrayList ();10 list.add("3333");11 list.add("444");12 map.put(student1, list);13 map.put(student2, list); 14 map.put(student, list);15 16 System.out.println(map);*/17 18 LinkedHashMap linkedHashMap=new LinkedHashMap ();19 ArrayList arrayList=new ArrayList ();20 arrayList.add("333");21 arrayList.add("999");22 arrayList.add("555");23 24 ArrayList arrayList1=new ArrayList ();25 arrayList1.add("AAA");26 arrayList1.add("EEE");27 arrayList1.add("QQQ");28 29 linkedHashMap.put("1",arrayList);30 linkedHashMap.put("1",arrayList1);31 32 Set keys=linkedHashMap.keySet();33 /*for (String string : keys) {34 System.out.println(string+"="+linkedHashMap.get(string));35 }*/36 java.util.Iterator iterator=keys.iterator();37 while(iterator.hasNext()){38 String key=iterator.next();39 System.out.println(key+"="+linkedHashMap.get(key));40 }41 42 43 }44 45 }