Dab tsi yog array pib hauv Java?
Dab tsi yog array pib hauv Java?

Video: Dab tsi yog array pib hauv Java?

Video: Dab tsi yog array pib hauv Java?
Video: lub tuam tsev no by all stars inspirational 2024, Kaum ib hlis
Anonim

Array Initialization . Ib array hauv Java yog ib hom khoom uas muaj peev xwm muaj ntau yam sib txawv. Lub ntsiab lus tseem ceeb uas yuav tsum nco ntsoov yog thaum tsim, primitive arrays yuav muaj qhov tseem ceeb raws li tau muab, tab sis cov khoom siv yuav yog null.

Raws li txoj cai, koj yuav pib qhov array hauv Java li cas?

Nws txhais tau tias koj tab tom muab ib qho array rau cov ntaub ntawv [10] uas tuaj yeem tuav tsuas yog ib qho khoom. Yog koj xav tau pib ib array , sim siv Array Initializer : int data = {10, 20, 30, 40, 50, 60, 71, 80, 90, 91}; // los yog int data; data = new int {10, 20, 30, 40, 50, 60, 71, 80, 90, 91}; Pom qhov txawv ntawm ob qhov kev tshaj tawm.

Tsis tas li ntawd, koj yuav pib qhov kev piav qhia li cas? Pib pib ntawm arrays . Lub initializer rau ib array yog ib daim ntawv teev cov kab lus sib cais ntawm cov kab lus tas li uas nyob rau hauv braces ({ }). Yog ib array yog ib nrab pib , cov ntsiab lus uas tsis yog pib tau txais tus nqi 0 ntawm hom tsim nyog. Tib yam siv rau cov ntsiab lus ntawm arrays nrog lub sijhawm khaws cia zoo li qub.

Yog li ntawd, dab tsi yog qhov int array pib rau hauv Java?

Txhua chav kawm variable, piv txwv variable, los yog array tiv thaiv yog pib nrog tus nqi pib thaum nws tsim (§15.9, §15.10): Rau hom byte, tus nqi qub yog xoom, uas yog, tus nqi ntawm (byte)0. Rau hom int , lub neej ntawd tus nqi yog xoom, uas yog, 0. Rau hom ntev, lub neej ntawd tus nqi yog xoom, uas yog, 0L.

Yuav ua li cas koj pib qhov loj ntawm ib qho array hauv Java?

Txhua yam khoom hauv a Java array yuav tsum muaj tib hom, piv txwv li, ib array tsis tuaj yeem tuav tus lej thiab ib txoj hlua tib lub sijhawm. Java arrays kuj muaj ib tug ruaj qhov loj , raws li lawv hloov tsis tau lawv qhov loj ntawm runtime.

Arrays hauv Java

  1. Xaiv hom ntaub ntawv.
  2. Tshaj tawm cov array.
  3. Instantiate lub array.
  4. Pib ua qhov tseem ceeb.
  5. Kuaj cov array.

Pom zoo: