3 Teb. Koj tsis tuaj yeem hloov kho qhov Sau thaum rov ua dua nws siv Iterator, tsuas yog Iterator. tshem tawm. Qhov no yuav ua haujlwm tshwj tsis yog thaum daim ntawv pib iteration npliag, qhov twg yuav tsis muaj qhov dhau los.
Peb puas tuaj yeem hloov kho sau thaum rov ua dua?
Nyob rau-txhua lub voj, peb tsis tuaj yeem hloov kho sau, nws yuav cuam tshuam ConcurrentModificationException ntawm qhov tod tes nrog iterator peb tuaj yeem hloov kho sau.
Peb puas tuaj yeem ntxiv cov khoom rau ArrayList thaum rov ua dua?
3. ArrayList listIterator - Ntxiv / Tshem tawm. ListIterator txhawb ntxiv thiab tshem tawm cov ntsiab lus hauv cov npe thaum peb tab tom rov ua dua nws.
Yuav ua li cas ntxiv rau ib daim ntawv thaum rov hais dua?
Siv npe. append rau ntxiv cov ntsiab lus rau ib daim ntawv thaum iterating hla cov npe
- a_list=["a", "b", "c"
- list_length=len(a_list)
- rau kuv hauv ntau yam (list_length):
- a_list. append("New Element")
- print(a_list)
Peb puas tuaj yeem ntxiv cov ntsiab lus siv iterator?
The Java Tutorial los ntawm Sun qhia qhov no tsis tuaj yeem: "Nco ntsoov tias Iterator. tshem tawm yog tib txoj hauv kev nyab xeeb los hloov kho cov khoom sau thaum iteration; tus cwj pwm tsis raug qhia yog tias qhov sau hauv qab tau hloov pauv lwm txoj hauv kev thaum lub iteration tab tom ua."