String class in JDK uses private final char value[]; to store constants. I wonder why it does not use private final String value.
Is there any reason related to performance or memory issues?
String class in jdk used private final char value[] ..
Here used means 'used to define the String class'. The writer of string class needed a container to store the value of the string, & while (s)he is still in process of writing String class, how can they use it?
e.g. While assembling a desktop, you don't start with a desktop itself - you start with some basic components like a CPU, screen, mouse, keyboard etc..
By the definition of String Class itself
The String class represents character strings.
So,if you not storing characters, Where does a String came :) ?
i can store the constants in a String object, again where does the String Object came ? From characters right ?Think the String class as a wrapper for char[].
So the class uses char[] to store the effective value... it Can't use a String (as you said) because String doesn't exist without a place to store the characters.
In other words the chars are used for character storage as a primitive type and you can't do in a different way.
class String { private final String value; ... }? Let that sink for a minute...