1. 程式人生 > >【五】可變字串與非可變字串

【五】可變字串與非可變字串

一、定長字串

       宣告方式1: String str =new String("as");

       宣告方式2: String str="as";

      equals(): 

           String s1 =new String("as");

           String s2 =new String("as");

           String s3="as";

           String s4="as";

           s1==s2 ×

           s1==s3 ×

           s3==s4 √

       ==與equals(),當比較物件為字串時,==比較的是 物件記憶體首地址,equals()比較內容。當為非字串時,都比較的是物件首地址

二、非定長字串

    StringBuffer

    StringBuilder