java String類說明

o_瓜田李下_o發表於2020-10-25

java String類說明

 

 

*********************

String 類

 

String

public final class String
    implements java.io.Serializable, Comparable<String>, CharSequence,
               Constable, ConstantDesc {  //String類用final修飾,不可被繼承修改

    @Stable
    private final byte[] value;           //使用位元組陣列儲存字串內容
                                          //value用final修飾,指向內容不可修改

    /**
     * The identifier of the encoding used to encode the bytes in
     * {@code value}. The supported values in this implementation are
     *
     * LATIN1
     * UTF16
     */
    private final byte coder;             //字串編碼方式,可選值:LATIN1、UTF16


    /** Cache the hash code for the string */
    private int hash;                     //快取字串hash值,預設0

    /**
     * Cache if the hash has been calculated as actually being zero, enabling
     * us to avoid recalculating this.
     */
    private boolean hashIsZero;           //hash是否為0,預設false
                                          //首次返回hashcode後,會用hash快取,隨後獲取hashcode時,直接返回hash,避免重複計算

    @java.io.Serial
    private static final long serialVersionUID = -6849794470754667710L;


    static final boolean COMPACT_STRINGS; //是否壓縮字串,預設:true

    static {
        COMPACT_STRINGS = true;
    }


    @java.io.Serial
    private static final ObjectStreamField[] serialPersistentFields =
        new ObjectStreamField[0];

 

 

*********************

字串拼接:+

 

 

 

相關文章