????Java???????Java????????????????Java?????к????????????????????г????Щ????Java????????????????
????1.Java????????????????Щ??????????
??????????????ж??м????????Java?汾?????????????Vector??Stack??HashTable??Array???????????????Java1.2????????????м??????????????????????????????????????÷?????????????Java??????????á???????????Java???????У????????????????????????????????????£?
??????1????ú???????????????????????????????????????
??????2????????t?????????????????????????????????
??????3????????JDK?????????????????????????????
??????4????????????????
????2.???????е???????????
????Java1.5?????????????е?????????????????????????????????????????????????????????????????????????????????????κ??????????????????????????????????????ClassCastException?????????????????????????????????????????????????????????????instanceOf???????????????????????????????????????????????????
????3.Java?????????????????Щ??
????Collection???????????????????????????????Щ?????????????Java?????????????κ?????????
????Set??????????????????????????????????????????н??????????????????????????
????List?????????????????????????????????????????????????κ?????List?????????任?????顣
????Map???????key???value?????.???Map????????????key?????key???????????value??
?????Щ??????????Queue??Dequeue??SortedSet??SortedMap??ListIterator??
????4.???Collection????Cloneable??Serializable????У?
????Collection?????????????????????????????????Щ?????Collection????????????????磬?Щ??List??Collection??????????????????????????Set??????????Collection???????????е?clone???????????????????????????????????????????????????Collection????????????????????????
??????????????????????????????л??????????????????á???????????????t?????ζ??????п???????л??????????????????????л???
?????????е?????????????????л?????????????????????????????????????t????????????????????л???
????5.???Map???????Collection????
????????Map????????????????????????????Map?????????????????Map??????Map???Collection???????壬????????
???????Map???Collection????????????????Map????key-value??????????key??value?б?????????????????????“??????”?淶??
????6.Iterator??????
????Iterator??????????κ?Collection????????????????Collection?????????????????????????????????????????Java???????е?Enumeration???????????????????????????????????
????7.Enumeration??Iterator????????
????Enumeration???????Iterator??????????????????檔Enumeration???????????????????????????????????Enumeration????Iterator????????????????????????????????????????????????????????
???????????????Java???????е?Enumeration????????????????????????????????Enumeration??????????????????????????????????????????????????????
????8.????????Iterator.add()????????????????????????
???????岻????????????Iterator??Э?鯔?????????????????????ListIterator????????add?????????????????????
????9.??ε????????????????????????????????????????????α?
??????????????Iterator?????????????????ú??????????????????У??????ж??????????????????塣
????10.Iterater??ListIterator???????????
??????1????????????Iterator??????Set??List???????ListIterator??????List??
??????2??Iterator????????????????LIstIterator????????????
??????3??ListIterator??Iterator????У??????????Щ????????????????????????滻?????????????????????????λ?á?
????11.???????List????Щ?????????
????List<String>strList=new ArrayList<>();
????//???for-each???
????for(String obj:strList){
????System.out.println(obj);
????}
????//using iterator
????Iterator<String>it=strList.iterator();
????while(it.hasNext()){
????String obj=it.next();
????System.out.println(obj);
????}
?????????????????????????????????????????????????????????????????????ConcurrentModificationException??
????12.?????????fail-fast?????????????????
????????????????????????????Iterator fail-fast?????鵱??????????κθ????????????κθ?????????ConcurrentModificationException??Collection??????Iterator?????????fail-fast???????ConcurrentHashMap??CopyOnWriteArrayList?????????????????
????13.fail-fast??fail-safe????????
????Iterator??fail-fast????????????????????????????????????????κθ???????Java.util???е????м???????????fail-fast?????java.util.concurrent?е???????fail-safe???Fail-fast?????????ConcurrentModificationException????fail-safe????????????ConcurrentModificationException??
????14.??????????????????α???ConcurrentModificationException??
?????????????????????????????ò???????????????ConcurrentModificationException?????????CopyOnWriteArrayList????????ArrayList??
????15.???Iterator?????о????????
????Iterator??????????????????????????????????????????????Ρ????????????????????Iterator????????????????Iterator????????
??????????????????????????fail-fast????fail-safe??????磬ArrayList????????fail-fast?????CopyOnWriteArrayList????????fail-safe???
????16.UnsupportedOperationException??????
????UnsupportedOperationException?????????????????????????JDK???????????????????????java.util.Collections.UnmodifiableCollection??????????add??remove????????????????
????17.??Java?У?HashMap????ι??????
????HashMap??Map.Entry????????????д洢key-value???HashMap??ù????????put??get?????У??????hashCode()??equals()???????????????????key-value?????put?????????HashMap???Key hashCode()????????????洢key-value?????????Entry?洢??LinkedList?У????????????entry???????equals()????????鴫???key?????????????????????????value??????????????????????μ?entry????檔?????????????key????get???????????????hashCode()??????????е?????????????equals()????????????Entry???????????????????????????????????
????????????HashMap?????????????????????????????????????HashMap????????????32???????????0.75????????????????????????????????????????????entry?????map???С??????????HashMap???map????????????1???????????????????????????2???????????????????????洢??????key-value??????綹????????????????????????????????????????????HashMap???г??????????????????
????18.hashCode()??equals()?????к???????
????HashMap???Key?????hashCode()??equals()?????????key-value????????????????????HashMap?л??????????Щ?????????????????Щ??????б????????????????????£????????Key????????????hashCode()??equals()?????HashMap??????????????????????????????????????洢????????????????????в?????洢????????????????hashCode()??equals()???????????????????????????????equals()??hashCode()??????????????1???
??????1?????o1.equals(o2)?????o1.hashCode()==o2.hashCode()?????true???
??????2?????o1.hashCode()==o2.hashCode()????????ζ??o1.equals(o2)???true??
????19.???????????κ??????Map??key??
???????????????κ??????Map??key????????????????????????????????
??????1?????????д??equals()??????????????дhashCode()??????
??????2????????????????????equals()??hashCode()?????????ο?????????Щ????
??????3????????????????equals()?????????hashCode()?????????
??????4??????????key?????????????????????????hashCode()??????????????????и?????????????????????????hashCode()??equals()??δ???????????????????????????????
???????磬?????????MyKey????HashMap?????????
????//?????MyKey??name??????????equals()??hashCode()??
????MyKey key=new MyKey('Pankaj');//assume hashCode=1234
????myHashMap.put(key??'Value');
????//???μ???????key??hashCode()??equals()?
????key.setName('Amit');//assume new hashCode=7890
????//???????null?????HashMap???????洢?????????key????key????????????????????null
????myHashMap.get(new MyKey('Pankaj'));
???????????String??Integer?????HashMap??key??????á?