Cov txheej txheem:

StringBuilder puas tuaj yeem ua tsis tau?
StringBuilder puas tuaj yeem ua tsis tau?

Video: StringBuilder puas tuaj yeem ua tsis tau?

Video: StringBuilder puas tuaj yeem ua tsis tau?
Video: Eann Woo Bin ABRSM violin Grade 1 Exam Pieces: Ode to Joy 2024, Hlis ntuj nqeg
Anonim

npliag txhais tau tias, uas tsis muaj cov cim hauv lub StringBuilder . null txhais tias tsis muaj StringBuilder yam khoom txhua. Qhov sib txawv tsuas yog null yog tias nws muaj hom siv (piv txwv li String, StringBuilder , Teem, raws li ib tug thumbrule: tag nrho cov capitalized hom) thiab nws tseem tsis tau pib los yog tau teem kom meej meej rau null.

Ib yam li ntawd, kuv yuav ua li cas thiaj paub yog tias kuv tus StringBuilder khoob?

Txoj kev ntev ntawm cov StringBuilder lossis StringBuffer chav kawm rov qab qhov ntev ntawm cov kab ke ntawm cov cim nws tam sim no muaj. Raws li koj tuaj yeem pom hauv qhov piv txwv, mus kuaj yog tias tus StringBuilder yog khoob , tau qhov ntev ntawm lub StringBuilder khoom. Yog ntev yog 0, nws yog khoob , txwv tsis pub.

Ib yam li ntawd, vim li cas StringBuilder muaj txiaj ntsig zoo dua li StringBuffer? Vim li ntawd, StringBuilder sai dua tshaj StringBuffer . StringBuffer yog mutable. Nws tuaj yeem hloov pauv ntawm qhov ntev thiab cov ntsiab lus. StringBuffers yog xov-kev nyab xeeb, txhais tau hais tias lawv muaj synchronized txoj kev los tswj kev nkag mus kom tsuas yog ib txoj xov tuaj yeem nkag mus rau a StringBuffer object's synchronized code ntawm ib lub sij hawm.

Raws li, koj yuav rov pib dua StringBuilder li cas?

1) Clear StringBuilder los ntawm kev muab cov khoom tshiab

  1. pej xeem chav JavaStringBufferClearEmptyExample {
  2. public static void main(String args) {
  3. StringBuilder sbStr = null;
  4. for(int i = 1; i <= 5; i++){
  5. // clear cov ntsiab lus los ntawm yav dhau los iteration.
  6. sbStr = new StringBuilder();
  7. sbStr. append(i);
  8. Qhov system. tawm. print(sbStr);

StringBuilder ua haujlwm sab hauv hauv Java li cas?

StringBuilder cov khoom zoo li String khoom, tshwj tsis yog tias lawv tuaj yeem hloov kho. Sab hauv , cov khoom no raug kho zoo li qhov sib txawv-ntev arrays uas muaj ib ntu ntawm cov cim. Piv txwv li, yog tias koj xav tau concatenate ntau ntawm cov hlua, ntxiv rau a StringBuilder khoom siv tau ntau dua.

Pom zoo: