1 package cn.itcast.p9.linkedhashmap.demo; 2 3 import java.util.HashMap; 4 import java.util.Iterator; 5 import java.util.LinkedHashMap; 6 import java.util.Map; 7 8 public class LinkedHashMapDemo { 9 10 public static void main(String[] args) { 11 // TODO Auto-generated method stub 12 HashMap<Integer, String> hm = new LinkedHashMap<Integer,String>(); 13 14 hm.put(7, "zhouqi"); 15 hm.put(3, "zhangsan"); 16 hm.put(1, "qianyi"); 17 hm.put(5, "wangwu"); 18 19 Iterator<Map.Entry<Integer, String>> it = hm.entrySet().iterator(); 20 21 while(it.hasNext()) { 22 Map.Entry<Integer, String> me = it.next(); 23 24 Integer key = me.getKey(); 25 String value = me.getValue(); 26 27 System.out.println(key+":"+value); 28 29 } 30 31 } 32 33 }LinkedHashMapDemo
关联源码:
如果剪切src文件到其它地方,虽然编辑器能访问到源码,但是是之前缓存的,点击ChangeAttached Source找到src文件位置就OK
注:以后用API通常是第三方工具,开源的话要记得下源代码,不要直接下API