Cov array puas tuaj yeem ua tsis tiav hauv Java?
Cov array puas tuaj yeem ua tsis tiav hauv Java?

Video: Cov array puas tuaj yeem ua tsis tiav hauv Java?

Video: Cov array puas tuaj yeem ua tsis tiav hauv Java?
Video: Ntsaim vaj - Muaj poj niam lawm ua tsis tau li cas ( Official MV ) Nkauj tawm tshiab 2020 2024, Kaum ib hlis
Anonim

Ib array muaj nws cov tswv cuab pib rau lawv cov nqi pib. Rau hauv lub neej ntawd yog 0. Rau ib yam khoom nws yog null . A null array yog a null Array Reference (txij thaum arrays yog hom siv hauv Java ).

Tsis tas li ntawd, koj tuaj yeem teeb tsa ib qho array rau null?

Yog koj muaj ib array ntawm integers thiab koj sim ua ib lub caij null koj ua tau 't ua arr = null ; vim integer tsis tuaj yeem hloov mus rau null . Tsis yog kiag li. Nyob rau hauv thawj rooj plaub koj 're kev teeb tsa tag nrho cov ntaub ntawv nyob rau hauv koj array rau null . Hauv qhov thib ob koj 're kev teeb tsa qhov siv heev rau lub array nws tus kheej rau null.

Ib yam li ntawd, koj siv null li cas hauv Java? Hauv Java (tm), " null " tsis yog lo lus tseem ceeb, tab sis qhov tshwj xeeb literal ntawm lub null hom. Nws tuaj yeem raug pov rau txhua hom kev siv, tab sis tsis yog rau txhua yam qub xws li int lossis boolean. Cov null literal tsis tas muaj nqi pes tsawg. Thiab nws yog tsis yooj yim sua kom nrum rau lub null hom lossis tshaj tawm qhov hloov pauv ntawm hom no.

Tom qab ntawd, ib tug kuj yuav nug, koj yuav ua li cas xyuas seb qhov array puas yog null lossis tsis?

  1. Siv suav Function: Qhov haujlwm no suav tag nrho cov ntsiab lus hauv ib qho array. Yog tias tus naj npawb ntawm cov ntsiab lus hauv array yog xoom, ces nws yuav tso tawm cov array khoob.
  2. Siv sizeof() muaj nuj nqi: Txoj kev no xyuas qhov loj ntawm array. Yog hais tias qhov loj ntawm array yog xoom ces array yog npliag txwv tsis pub array tsis yog khoob.

Yuav ua li cas kos array yog null lossis tsis nyob hauv Javascript?

Cov array tuaj yeem kuaj xyuas yog tias nws yog khoob los ntawm kev siv lub array . ntev khoom. Los ntawm kev tshuaj xyuas yog tias muaj khoom muaj, nws tuaj yeem ua kom paub tseeb tias nws yog ib qho array , thiab by kev tshuaj xyuas yog tias qhov ntev xa rov qab ntau dua 0, nws tuaj yeem paub tseeb tias qhov array yog tsis khoob.

Pom zoo: