< prev index next >

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

Print this page

        

@@ -128,16 +128,21 @@
      */
     private static final ObjectStreamField[] serialPersistentFields =
         new ObjectStreamField[0];
 
     /**
+     * a shared instance of the string value for empty strings.
+     */
+    private static final char[] EMPTY_STRING_VALUE = new char[0];
+
+    /**
      * Initializes a newly created {@code String} object so that it represents
      * an empty character sequence.  Note that use of this constructor is
      * unnecessary since Strings are immutable.
      */
     public String() {
-        this.value = new char[0];
+        this.value = EMPTY_STRING_VALUE;
     }
 
     /**
      * Initializes a newly created {@code String} object so that it represents
      * the same sequence of characters as the argument; in other words, the
< prev index next >