Cov txheej txheem:

Yuav siv HashMap tau txoj hauv kev li cas?
Yuav siv HashMap tau txoj hauv kev li cas?

Video: Yuav siv HashMap tau txoj hauv kev li cas?

Video: Yuav siv HashMap tau txoj hauv kev li cas?
Video: Siv Yis Neeb Leej Cawm Seej Music Video Short 2024, Kaum ib hlis
Anonim

java ua. siv. HashMap. get() Method

  1. Kev piav qhia. Cov tau (Object key) txoj kev yog siv rau rov qab tus nqi rau uas tus yuam sij teev yog mapped, los yog null yog tias daim ntawv qhia no tsis muaj daim ntawv qhia rau tus yuam sij.
  2. Tshaj tawm. Hauv qab no yog cov lus tshaj tawm rau java.
  3. Tsis muaj.
  4. Rov qab tus nqi.
  5. Kev zam.
  6. Piv txwv.

Kuj nug, GET txoj kev ua haujlwm li cas hauv HashMap?

Ua haujlwm ntawm HashMap hauv Java

  1. equals(): Nws xyuas qhov sib npaug ntawm ob yam khoom. Nws muab piv rau Cov Ntsiab Cai, seb lawv sib npaug los tsis yog.
  2. hashCode(): Nov yog txoj hauv kev ntawm chav kawm khoom. Nws xa rov qab lub cim xeeb siv ntawm cov khoom nyob rau hauv integer daim ntawv.
  3. thoob: Array ntawm node yog hu ua thoob. Txhua lub node muaj cov qauv ntaub ntawv zoo li LinkedList.

Tom qab ntawd, lo lus nug yog, koj yuav nrhiav tus nqi ntawm daim ntawv qhia li cas? Feem ntau, kom tau txais tag nrho cov yuam sij thiab qhov tseem ceeb los ntawm daim ntawv qhia, koj yuav tsum ua raws li cov theem hauv qab no:

  1. Hloov Hashmap rau MapSet kom tau txais cov txheej txheem nkag hauv Daim Ntawv Qhia nrog entryset() txoj kev.: Teem st = daim ntawv qhia.
  2. Tau txais iterator ntawm cov teeb no: Iterator nws = st.
  3. Tau daim ntawv qhia.
  4. siv getKey() thiab getValue() txoj hauv kev ntawm Daim Ntawv Qhia.

Ib tug kuj yuav nug, dab tsi yog txoj hauv kev hauv HashMap?

HashMap Cov txheej txheem chav kawm hauv Java nrog Piv txwv | Teem 1 (put(), get(), isEmpty() thiab size()) HashMap yog cov qauv ntaub ntawv uas siv hash muaj nuj nqi rau daim ntawv qhia kev txheeb xyuas qhov tseem ceeb, hu ua cov yuam sij, rau lawv cov txiaj ntsig cuam tshuam. Nws muaj "tus nqi tseem ceeb" ua khub thiab tso cai rau rov muab tus nqi los ntawm tus yuam sij. Map myhash = Collections.

HashMap muajValue ua haujlwm li cas?

HashMap . muajValue () txoj kev yog siv los xyuas seb tus nqi tshwj xeeb yog tau mapped los ntawm ib tug los yog ntau tshaj ib tug yuam sij nyob rau hauv lub HashMap . Nws yuav siv tus nqi raws li qhov parameter thiab rov qab muaj tseeb yog tias tus nqi ntawd yog mapped los ntawm ib qho ntawm tus yuam sij hauv daim ntawv qhia. Program 1: Mapping String Values to Integer Keys.

Pom zoo: