?????Java??????????????????眉????Collection???????????Java API???????????????

????????Java API?????????????????????Collection??????????????薪????锟�?

                  Collection<--List<--Vector
                  Collection<--List<--ArrayList
                  Collection<--List<--LinkedList
                  Collection<--Set<--HashSet
                  Collection<--Set<--HashSet<--LinkedHashSet
                  Collection<--Set<--SortedSet<--TreeSet

Vector : ????Array??List???????????Array??????????些??????????????????????????Array????????????????????Array?????????????????锟�????????????Array?????????????????Vector??????????????????sychronized”?????????Vector??ArrayList???????

ArrayList???Vector????????????Array??????????????????ArrayList?????????????????????????Vector????些??????????械??????????????????????????????????????

LinkedList??LinkedList????????????List???????????Array??????????Array???????????????????Node????????????????????1.???????????data????2.??????????????nextNode???????????LinkedList?????????????????????????Array??List???????????写????????????????????nextNode??????????????????????LinkedList???????

List???

1. ???械?List???????????????????????????????????Key??Value?????????纾篬 tom??1??c ]??

2. ???械?List?锌??????????????????Vector?锌????? [ tom??koo??too??koo ]??

3. ???械?List?锌?????null????????[ tom??null??1 ]??

4. ????Array??List??Vector??ArrayList???????????LinkedList???????????????????????

HashSet?????Set?List???????Collection??????????????????????????List???????????Array???????????Set??????HashMap???????????????????Set??List?????????HashSet??娲�??????HashMap?械?Key???Set?????娲�?睢�????HashSet??add??Object  obj??????????????????????
    public boolean add(Object obj)
    {
        return map.put(obj?? PRESENT) == null;
    }

???????????Set?胁???????List????????????????????????HashMap??key?????????????

LinkedHashSet??HashSet?????????????????

TreeSet??SortedSet?????????????HashSet???????TreeSet???????????????SortedMap???????

Set???

1. Set?????????Map??HashMap????

2.  Set?械?????????????????????add(Object obj)??????????????????????????????

??????眉????? ?

????????????????????????????????????????????卤????????????????????????????????

 
???????

??????????java.util???小?
??????????????????????????????????????????????????????械????????????卸?????????reference)??
?????????????3???set(??????list(?斜????map(???)??

(1)??
????set?????????????????????????????????????????????????校????????????????
????谐???????????????????卸???????y??械????????胁????????????
????卸?????澹�??????????????????TreeSet????????????????械???????????????????????????????????????小?????????SortedSet??????????????????????????????械????????????????????????????????

(2)?斜?
?斜?????????????????????????娲�???????????????????????????尾?????????????????????????????
?斜?????????蟹????????????????????????????????小?
????????斜?????????????????????芯??????????????????????????

(3)???
????????斜???????????????????????????????写娲�???????????????????????Key?????????????????????????械?娲⑽�????????????????????????????????????胁榈�???????????????????
?????????????????????娲⑽�?????????????????(hashing)?????????????????????????????(hash code)?????????

??????????????????????????????????????????????????????位???????????????/??????娲⑽�?谩?????????锟�???写?????貌?????????围??????????????????????????????????????

????????
java.util?泄???13?????????????????????????????斜??????????????????些????????

????
HashSet?? ???HashMap????????????????????????????????????????????????效??????????????????HashMap??????????娲�????????????????????????.

TreeSet?? ???????????????????????????????味??????TreeSet??????????????????????????????TreeSet??????????TreeMap.

?斜??
Vector?? ?????????????????????????????????????????????????????卤?娲�???????????????????????????????????????????????????????Vector?屑???????Vector????????????!!?????????????????????????????????

Stsck: ??????Vector???????????????????????????!??????????娲�????

LinkedList: ?????????????????????????????????????????????谩?

ArrayList: ?????????椋�??????????????????????????????????????????Vector?????????


???
HashTable?? ????????????械???????????????效??????????????????????hashcode()??????equal()????????????????java?????????校??????????????????????????懈??????谩?

HashMap?? ?????????????娲�??????????????????????????????????????????????

WeakHashMap?? ???????????????????????????????????????????????/??????????????????HashMap?纬?????????械??????/????????????????????????????????卸??????????????????????????

TreeMap?? ?????????????????????????????械??

Set??List????????????Collection?????????????????????????????????Collection??????????谩?????味???魏??斜?????????????????????????????????????????????????????????????????????????斜?????????????????斜???????????????????????Collection??????????

Vector ????ArrayList?????????????????
????????????????????????????Vector??????????ArrayList???????????????????????????????????????????????????????????????????????????4?????????????

(1)API

(2)???????

(3)??????????

(4)?????

?????????4??????????????

API
????Ken Arnold????????Java Programming Language??(Addison-Wesley?? June 2000)???????????????????Vector??????ArrayList.?????写?API????????????????????????????????????????些???????????

?????

Vector??????????????械??些?????????Vector?械????????????????ArrayList????????????ArrayList?械?????????????????????????????????械?效???????????????????????????????ArrayList???????????????????????????????????????????????????

????????

???????????????ArrayList??Vector???????????(Array)??????????械??????????????????????????????????????????????????????????????????????????????????????Vector?????????????????????????槌�???ArrayList???????50%????????????????????????????????????????????????????????????斜??????????????????Vector???些???????????????????眉??????????小????????????????????

?????

??ArrayList??Vector?校???????????位??????????????????????????????尾????????????????????????????????????????????O(1)???????????????????????位????????????????????????????????????O(n-i)??????n??????????????????i???????????????????????位?谩?????????????????????????????????????械?i???i?????????????????????位???????????????味???????
????味??????????????位???????????????????????????????????Vector??ArrayList??????????????????????????????????????????
???纾琇inkList???????????????????????魏?位???????????????????????—O(1)??????????????????????????????O(i)??????i????????位??.???ArrayList???????????????????????????????娲�??iterator??????????LinkList???????????????????????????????????????????????????

?????Practical Java???????Peter Haggar?????????????????楗桝rray????????Vector??ArrayList??????????????效??????????????????????????(Array)??????????????????????煤??????????路???????????