< prev index next >

src/java.base/share/classes/java/lang/String.java

Print this page




 113     /** The value is used for character storage. */
 114     private final char value[];
 115 
 116     /** Cache the hash code for the string */
 117     private int hash; // Default to 0
 118 
 119     /** use serialVersionUID from JDK 1.0.2 for interoperability */
 120     private static final long serialVersionUID = -6849794470754667710L;
 121 
 122     /**
 123      * Class String is special cased within the Serialization Stream Protocol.
 124      *
 125      * A String instance is written into an ObjectOutputStream according to
 126      * <a href="{@docRoot}/../platform/serialization/spec/output.html">
 127      * Object Serialization Specification, Section 6.2, "Stream Elements"</a>
 128      */
 129     private static final ObjectStreamField[] serialPersistentFields =
 130         new ObjectStreamField[0];
 131 
 132     /**





 133      * Initializes a newly created {@code String} object so that it represents
 134      * an empty character sequence.  Note that use of this constructor is
 135      * unnecessary since Strings are immutable.
 136      */
 137     public String() {
 138         this.value = new char[0];
 139     }
 140 
 141     /**
 142      * Initializes a newly created {@code String} object so that it represents
 143      * the same sequence of characters as the argument; in other words, the
 144      * newly created string is a copy of the argument string. Unless an
 145      * explicit copy of {@code original} is needed, use of this constructor is
 146      * unnecessary since Strings are immutable.
 147      *
 148      * @param  original
 149      *         A {@code String}
 150      */
 151     public String(String original) {
 152         this.value = original.value;
 153         this.hash = original.hash;
 154     }
 155 
 156     /**
 157      * Allocates a new {@code String} so that it represents the sequence of
 158      * characters currently contained in the character array argument. The




 113     /** The value is used for character storage. */
 114     private final char value[];
 115 
 116     /** Cache the hash code for the string */
 117     private int hash; // Default to 0
 118 
 119     /** use serialVersionUID from JDK 1.0.2 for interoperability */
 120     private static final long serialVersionUID = -6849794470754667710L;
 121 
 122     /**
 123      * Class String is special cased within the Serialization Stream Protocol.
 124      *
 125      * A String instance is written into an ObjectOutputStream according to
 126      * <a href="{@docRoot}/../platform/serialization/spec/output.html">
 127      * Object Serialization Specification, Section 6.2, "Stream Elements"</a>
 128      */
 129     private static final ObjectStreamField[] serialPersistentFields =
 130         new ObjectStreamField[0];
 131     
 132     /**
 133      * a shared instance of the string value for empty strings.
 134      */
 135     private static final char[] EMPTY_STRING_VALUE = new char[0];
 136 
 137     /**
 138      * Initializes a newly created {@code String} object so that it represents
 139      * an empty character sequence.  Note that use of this constructor is
 140      * unnecessary since Strings are immutable.
 141      */
 142     public String() {
 143         this.value = EMPTY_STRING_VALUE;
 144     }
 145 
 146     /**
 147      * Initializes a newly created {@code String} object so that it represents
 148      * the same sequence of characters as the argument; in other words, the
 149      * newly created string is a copy of the argument string. Unless an
 150      * explicit copy of {@code original} is needed, use of this constructor is
 151      * unnecessary since Strings are immutable.
 152      *
 153      * @param  original
 154      *         A {@code String}
 155      */
 156     public String(String original) {
 157         this.value = original.value;
 158         this.hash = original.hash;
 159     }
 160 
 161     /**
 162      * Allocates a new {@code String} so that it represents the sequence of
 163      * characters currently contained in the character array argument. The


< prev index next >