Koj puas tuaj yeem ntxiv null rau lub teeb Java?
Koj puas tuaj yeem ntxiv null rau lub teeb Java?

Video: Koj puas tuaj yeem ntxiv null rau lub teeb Java?

Video: Koj puas tuaj yeem ntxiv null rau lub teeb Java?
Video: txhob hnov qab kuv lub npe - Bee lee [Official MV] 2022-23 2024, Kaum ib hlis
Anonim

Raws li kev txhais a teeb khoom ua tsis pub duplicate qhov tseem ceeb tab sis nws ua pub ntau tshaj ib null tus nqi. Null Cov nqi hauv HashSet - Cov khoom HashSet tso cai null tus nqi tab sis, koj tuaj yeem ntxiv nkaus xwb ib null element rau nws. Txawm li cas los koj ntxiv ntau null nqi yog koj sim luam nws cov ntsiab lus, nws tsuas pom ib null.

Ib yam li ntawd, peb puas tuaj yeem ntxiv null hauv cov npe Java?

Cov npe tso cai kom muaj null , yog li koj tuaj yeem muab null hauv nws yog tias koj xav tau. Ib qho ArrayList meej tau tso cai thiab tuaj yeem khaws cia null qhov tseem ceeb, vim lawv yuav muaj txiaj ntsig rau koj qhov kev pab cuam. Thiab khoob lis yog khoob (piv txwv li tsis muaj dab tsi, tsis txawm null.

Tom qab, lo lus nug yog, uas Java sau tsis tso cai null? HashSet hauv Java. Chav kawm HashSet siv lub teeb interface, txhawb nqa los ntawm lub rooj hash uas yog qhov tseeb HashMap piv txwv. Tsis muaj kev lav phib xaub raws li qhov kev txiav txim iteration ntawm cov txheej txheem uas txhais tau hais tias cov chav kawm tsis lav qhov kev txiav txim tas li ntawm cov ntsiab lus dhau sijhawm. Chav kawm no tso cai rau null keeb.

Ib yam li ntawd, HashSet puas tso cai rau null qhov tseem ceeb hauv Java?

HashSet ua tsis yog tso cai duplicate cov ntsiab lus uas txhais tau tias koj ua tau tsis khaws duplicate tus nqi hauv HashSet . HashMap ua tsis yog tso cai duplicate yuam sij txawm li cas los nws tso cai kom muaj duplicate tus nqi . HashSet tso cai kom muaj ib leeg nqi null . HashMap tso cai rau ib leeg null qhov tseem ceeb thiab ib tus lej ntawm nuj nqis null.

Koj muab tus nqi li cas rau null hauv Java?

Hauv Java , a nqi null tuaj yeem raug xa mus rau ib qho khoom siv ntawm txhua hom los qhia tias nws taw qhia tsis muaj dab tsi. Lub compiler muab null rau ib qho uninitialized static thiab piv txwv cov tswv cuab ntawm hom siv. Thaum tsis muaj tus tsim qauv, getArticles() thiab getName() txoj kev yuav rov qab a null siv.

Pom zoo: