Kev siv StringBuffer hauv Java yog dab tsi?
Kev siv StringBuffer hauv Java yog dab tsi?

Video: Kev siv StringBuffer hauv Java yog dab tsi?

Video: Kev siv StringBuffer hauv Java yog dab tsi?
Video: looj phaj kev siv 2024, Kaum ib hlis
Anonim

StringBuffer hauv java yog siv los tsim cov khoom siv String hloov tau. Qhov no txhais tau tias peb ua tau siv StringBuffer txhawm rau ntxiv, thim rov qab, hloov, sib txuas thiab tswj cov hlua lossis cov cim kab ke. Cov txheej txheem sib xws hauv qab StringBuffer chav kawm raug tsim los ua raws li cov haujlwm no.

Raws li, StringBuffer yog dab tsi hauv Java nrog piv txwv?

StringBuffer chav kawm hauv Java . StringBuffer yog ib chav kawm ua phooj ywg ntawm String uas muab ntau qhov kev ua haujlwm ntawm cov hlua. StringBuffer (Txoj hlua str): Nws lees txais ib txoj hlua sib cav uas teeb tsa cov ntsiab lus pib ntawm tus StringBuffer khoom thiab reserves chav rau 16 tus cim ntxiv yam tsis muaj chaw nyob.

Tom qab ntawd, lo lus nug yog, qhov txawv ntawm txoj hlua thiab StringBuffer yog dab tsi? String thiab StringBuffer ob leeg yog cov chav kawm uas ua haujlwm rau hlua . StringBuffer chav kawm yog cov phooj ywg ntawm chav kawm Txoj hlua . Qhov yooj yim Qhov sib txawv ntawm String thiab StringBuffer yog qhov khoom ntawm " Txoj hlua ” chav kawm yog hloov tsis tau. Cov khoom ntawm chav kawm " StringBuffer ” mutable.

Ua raws li qhov no, thaum twg kuv yuav tsum siv StringBuffer?

Yog tias qhov khoom muaj nqis tuaj yeem hloov pauv thiab tsuas yog nkag los ntawm ib qho xov nkaus xwb, siv StringBuilder vim StringBuilder yog unsynchronized. Nyob rau hauv rooj plaub uas tus nqi khoom tuaj yeem hloov pauv, thiab yuav raug hloov los ntawm ntau cov xov, siv a StringBuffer vim StringBuffer yog synchronized.

Yuav ua li cas koj tshaj tawm txoj hlua tsis nyob hauv Java?

A txoj hlua tsis muaj zoo li a Txoj hlua , tab sis tuaj yeem hloov kho. Nws muaj qee qhov tshwj xeeb ntawm cov cim, tab sis qhov ntev thiab cov ntsiab lus ntawm cov kab ke tuaj yeem hloov pauv los ntawm qee txoj kev hu. Lawv muaj kev nyab xeeb rau kev siv los ntawm ntau cov xov. Txhua txoj hlua tsis muaj muaj peev xwm.

Pom zoo: