Cov txheej txheem:

Yuav ua li cas koj paub yog tias ob Hashmaps sib npaug?
Yuav ua li cas koj paub yog tias ob Hashmaps sib npaug?

Video: Yuav ua li cas koj paub yog tias ob Hashmaps sib npaug?

Video: Yuav ua li cas koj paub yog tias ob Hashmaps sib npaug?
Video: Kuv Hmoov Phem Los Koj Siab Phem-LOKY(Official MV ) 2024, Kaum ib hlis
Anonim

Yog peb xav muab piv hashmaps los ntawm keys i.e. ob hashmap yuav yog sib npaug yog tias lawv muaj cov yuam sij tib yam, peb tuaj yeem siv HashMap . keySet() muaj nuj nqi. Nws rov qab tag nrho daim ntawv qhia yuam sij hauv HashSet. Peb tuaj yeem sib piv cov hashset ntawm cov yuam sij rau ob qho tib si daim ntawv qhia siv Set.

Ib yam li ntawd, koj ua li cas piv ob qhov txiaj ntsig ntawm daim duab qhia?

Txoj hauv kev kom yog los sib piv cov duab qhia txog tus nqi sib npaug yog:

  1. Txheeb xyuas tias daim duab qhia chaw yog tib qhov loj (!)
  2. Tau cov yuam sij ntawm ib daim ntawv qhia.
  3. Rau txhua tus yuam sij los ntawm qhov teeb tsa koj tau rov qab, xyuas tias tus nqi muab los ntawm txhua daim ntawv qhia rau tus yuam sij ntawd yog tib yam (yog tias tus yuam sij tsis tuaj ntawm ib daim ntawv qhia, qhov ntawd yog tag nrho tsis ua tiav ntawm kev sib npaug)

Tsis tas li ntawd, entrySet thiab keySet yog dab tsi hauv Java? Cov java ua .util. Map interface muab peb txoj hauv kev keySet (), qhov tseem ceeb () thiab nkagSet (), uas tso cai rau ib daim ntawv qhia cov ntsiab lus saib raws li ib txheej ntawm cov yuam sij, sau cov txiaj ntsig, lossis cov txheej txheem ntawm qhov tseem ceeb-tus nqi sib piv.

Kuj nug, koj ua li cas piv ob Arraylists?

Koj ua tau piv ob array npe siv cov equals() method of the ArrayList chav kawm, txoj kev no lees txais cov npe khoom raws li qhov ntsuas, piv nrog cov khoom tam sim no, nyob rau hauv rooj plaub ntawm qhov sib tw nws rov qab muaj tseeb thiab yog tias tsis yog nws rov qab tsis tseeb.

HashMap yog dab tsi hauv Java?

HashMap yog ib feem ntawm Java cov sau txij thaum Java 1.2. Nws muab cov kev siv yooj yim ntawm Daim Ntawv Qhia interface ntawm Java . Nws khaws cov ntaub ntawv hauv (Key, Tus Nqi) ua khub. Txhawm rau nkag mus rau tus nqi ib tus yuav tsum paub nws qhov tseem ceeb. HashMap yog lub npe hu ua HashMap vim nws siv cov txheej txheem hu ua Hashing.

Pom zoo: