The String class
The String class contrasts with Character in that a String object stores a sequence of characters—a string—whereas a Character object stores one character. Because strings are pervasive in text-processing and other programs, Java offers two features that simplify developer interaction with String objects: simplified assignment and an operator that concatenates strings. This section examines those features.
String objects
A java.lang.String object stores a character sequence in a character array that String's private value field variable references. Furthermore, String's private count integer field variable maintains the number of characters in that array. Each String has its own copy of those fields, and Java's simplified assignment shortcut offers the easiest way to create a String and store a string in the String's value array, as the following code demonstrates:
public static void main (String [] args)
{
String s = "abc";
System.out.println (s); // Output: abc
}
No comments:
Post a Comment