Vim li cas iterator tseem ceeb?

Cov txheej txheem:

Vim li cas iterator tseem ceeb?
Vim li cas iterator tseem ceeb?
Anonim

Lub hom phiaj tseem ceeb ntawm tus neeg siv khoom yog tso cai rau tus neeg siv ua txhua yam ntawm lub thawv thaum cais tus neeg siv los ntawm cov qauv sab hauv ntawm lub thawv. Qhov no tso cai rau lub thawv khaws cov khoom hauv txhua yam uas nws xav tau thaum tso cai rau tus neeg siv los kho nws zoo li nws yog ib qho yooj yim ib ntus lossis npe.

Yuav ua li cas yog txoj hauv kev tseem ceeb hauv iterator?

Iterator interface txhais peb txoj hauv kev raws li hauv qab no:

  • Rov qab muaj tseeb yog tias qhov iteration muaj ntau cov ntsiab lus pej xeem boolean muajNext;
  • Rov qab cov ntsiab lus tom ntej hauv qhov rov ua dua. Nws cuam NoSuchElementException yog tias tsis muaj cov ntsiab lus ntxiv rau pej xeem Object tom ntej;
  • Tshem tawm cov ntsiab lus tom ntej hauv qhov rov ua dua.

Vim li cas iterator zoo dua rau lub voj?

Iterator thiab rau-txhua lub voj yog nrawm dua li yooj yim rau lub voj rau cov khoom sau uas tsis muaj kev nkag mus tsis tau, thaum nyob hauv cov khoom sau uas tso cai rau kev nkag mus tsis muaj kev hloov pauv nrog rau-txhua Loop/rau Loop/Iterator.

Lub hom phiaj ntawm iterator Cheebtsam yog dab tsi?

Lub hom phiaj ntawm Iterator tivthaiv yog txhawm rau muab lub tswv yim rau kev rov ua dua cov ntsiab lus ntawm ib qho khoom thiab nthuav tawm txhua lub ntsiab lus raws li cov khoom sib cais.

Dab tsi yog qhov zoo ntawm iterating ib qho khoom siv iterator?

Qhov zoo ntawm Iterator hauv Java

Iterator hauv Java txhawb nqa ob qho tib si nyeem thiab tshem tawm haujlwm. Yog tias koj siv rau lub voj voog kojtsis tuaj yeem hloov kho (ntxiv / tshem tawm) Cov Sau thaum nrog kev pab los ntawm tus iterator koj tuaj yeem hloov kho Sau tau yooj yim. Nws yog Universal Cursor rau Collection API.

Pom zoo: