1.泛型-->只在編譯階段有作用,在運行階段會丟棄具體的類型
ArrayList<Integer> collection1 = new ArrayList<Integer>();
ArrayList<String> collection2 = new ArrayList<String>();
System.out.println(collection1.getClass() == collection2.getClass())
結果:true
2.泛型小例子
HashMap<String, Integer> maps = new HashMap<String, Integer>();
maps.put("阿安", 18);
maps.put("阿三", 40);
maps.put("狗四", 33);
Set<Map.Entry<String,Integer>> entrySet = maps.entrySet(); //爲了能使hashmap疊代,使用enreySet轉化爲Set
for(Map.Entry<String, Integer> entry : entrySet){
System.out.println(entry.getKey() + " : " + entry.getValue());
}