Cov txheej txheem:

Yuav ua li cas tshem tawm qhov Performance index ntawm ArrayList?
Yuav ua li cas tshem tawm qhov Performance index ntawm ArrayList?

Video: Yuav ua li cas tshem tawm qhov Performance index ntawm ArrayList?

Video: Yuav ua li cas tshem tawm qhov Performance index ntawm ArrayList?
Video: Tseem Ev Lub Kawm - Koos Loos 2024, Kaum ib hlis
Anonim

tshem tawm (int qhov ntsuas ) – tshem tawm los ntawm arraylist ntawm qhov teev tseg qhov ntsuas . Txoj kev no tshem tawm cov kev teev tseg keeb E ntawm qhov teev tseg txoj hauj lwm hauv daim ntawv no. Nws tshem tawm cov keeb tam sim no ntawm qhov ntawd txoj hauj lwm thiab tag nrho cov tom ntej cov ntsiab lus tau tsiv mus rau sab laug (yuav rho ib qho rau lawv ntsuas ). Index pib 0.

Ib yam li ntawd, nws tau nug, koj yuav ua li cas tshem tawm qhov ntsuas ntawm ArrayList hauv Java?

Muaj ob txoj hauv kev los tshem tawm cov khoom los ntawm ArrayList

  1. Los ntawm kev siv tshem tawm () txoj kev: ArrayList muab ob txoj kev tshem tawm ntau dhau. a.
  2. tshem tawm (int index): Txais qhov ntsuas ntawm cov khoom yuav raug tshem tawm. b.
  3. tshem tawm (Obejct obj): Txais khoom kom raug tshem tawm.

Tsis tas li ntawd, yuav ua li cas thaum koj tshem tawm ib lub ntsiab lus los ntawm ArrayList? Ib ArrayList yog ib daim ntawv teev npe sib law liag ntawm cov khoom uas tuaj yeem siv los ntawm qhov ntsuas. Yog li thaum koj rho tawm ib yam khoom , tag nrho cov khoom hauv qab no yuav raug hloov. Cov ntsiab lus yuav hloov. Raws li javadoc rau cov tshem tawm txoj kev uas seem nkag yuav hloov rov qab kom tsis muaj qhov khoob.

Qhov thib ob, koj yuav tshem tawm ib yam dab tsi los ntawm ArrayList li cas?

Muaj ob txoj hauv kev tshem tawm cov khoom los ntawm ArrayList hauv Java, ua ntej, siv tshem tawm () txoj kev, thiab thib ob los ntawm kev siv Iterator. ArrayList muab overloaded tshem tawm () txoj kev, ib qho lees txais qhov ntsuas ntawm cov khoom kom raug tshem tawm i.e. tshem tawm (int index), thiab lwm yam txais khoom yuav raug tshem tawm, i.e. tshem tawm (Object obj).

Yuav ua li cas koj tshem tawm ib lub caij los ntawm ArrayList thaum iterating?

Txawm tias java. siv. ArrayList muab cov tshem tawm () txoj kev, eg. tshem tawm (Index) thiab tshem tawm (Qhov khoom keeb ), koj tsis tuaj yeem siv lawv rau tshem tawm cov khoom thaum iterating dhau ArrayList hauv Java vim lawv yuav pov ConcurrentModificationException yog hu ua thaum rov hais dua.

Pom zoo: