????Map???
????1.?????????
????2.????map???????????????????????????????
????3.???map?????е?????

 

package Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class MapTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
entrySet();
}
//???????????keySet();
public static void keySet(){
HashMap<Students??String> hm   = new HashMap<Students??String>();
hm.put(new Students("lisi1"??21)?? "beijing");
hm.put(new Students("lisi1"??21)?? "tianjing");
hm.put(new Students("lisi4"??33)?? "nanjing");
hm.put(new Students("lisi8"??44)?? "ganzhou");
hm.put(new Students("lisi5"??80)?? "hengyang");
Set<Students> keyset  =hm.keySet();
for(Iterator<Students> it = keyset.iterator();it.hasNext();){
Students key =it.next();
String addrv =hm.get(key);
System.out.println(key+":::"+addrv);
}
}
public static void entrySet(){
HashMap<Students??String> hm   = new HashMap<Students??String>();
hm.put(new Students("lisi1"??21)?? "beijing");
hm.put(new Students("lisi1"??21)?? "tianjing");
hm.put(new Students("lisi4"??33)?? "nanjing");
hm.put(new Students("lisi8"??44)?? "ganzhou");
hm.put(new Students("lisi5"??80)?? "hengyang");
Set<Map.Entry<Students?? String>> entryset = hm.entrySet();
for(Iterator<Map.Entry<Students?? String>> it =entryset.iterator();it.hasNext();){
Map.Entry<Students?? String> entry = it.next();
Students s = entry.getKey();
String addr = entry.getValue();
System.out.println(s+":::"+addr);
}
}
}

????????
???????????
??????Java SE 1.5??????з??????????£??????????Object????????????????“????”??“????”????????????????????????????????????????????????????????????????????е?????????????????????????????????????????????????е????????????????????????????
?????????????<E>????????????ArrayList<E>?????<E>????????E?????????????ArrayList???????????洢E?????????
????????????????????????????????????????????????????????
?????????
????1???????????????????ClassCastException???????????????????????????????????????????
????2???????????????鷳??
???????

 

import java.util.*;
class GenericDemo{
public static void main(String[] args){
//?????????String??????????б?
ArrayList<String> al = new ArrayList<String>();
al.add("abc002");
al.add("abc013");
al.add("abc256");
al.add("abc028");
//al.add(4);//al.add(new Integer(5));
//?????????÷???
Iterator<String> it = al.iterator();
while(it.hasNext()){
String s = it.next();
System.out.println(s);
}
}
}
/*
???
abc002
abc013
abc256
abc028
*/