What is the base container in Java String?

Is it just a char array?

+6
java string
source share
1 answer

Yes, as well as some metadata, such as the start and end index (since this char array can be split between lines, for example, when creating substrings).

Looking at the source java.lang.String , you will see the following instance fields:

 /** The value is used for character storage. */ private final char value[]; /** The offset is the first index of the storage that is used. */ private final int offset; /** The count is the number of characters in the String. */ private final int count; /** Cache the hash code for the string */ private int hash; // Default to 0 
+10
source share

All Articles