String in java is a sequence of characters. String is more like a utility class which works
on that character sequence. This character sequence is maintained as a array called value[], for example
private final char value[];
String internally defines two private variables called offset and count to manage the char array. The declarations can be as shown
below:
/** 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;
Everytime we create a substring from any string object, substring() method assigns the new values of offset and count variables.
The internal char array is unchanged. This is a possible source of memory leak if substring() method is used without care.
|