Strings are sequences of Unicode characters. In many programming languages strings are are stored in arrays of characters. However, in Java strings are a separate object type, String. The "+" operator is used for concatenation, but all other operations on strings are done with methods in the String class.
See the Summary - Strings for an overview of the methods in String and related classes.
String |
The basic class for strings. String objects can NOT be changed. |
char |
Primitive type for 16-bit Unicode characters. |
Character |
Primarily useful for its utility functions for working with characters. |
StringBuffer |
StringBuffers are used to build or change strings. Conversion between String and StringBuffer is easy. |
StringBuilder |
StringBuilder was added in Java 5. It is the same as StringBuilder, but slightly faster because it's unsynchronized. |
StringTokenizer |
Used to break a String into tokens (words). |
BufferedReaderBufferedWriter |
Useful for reading and writing text files. |
Pattern, Matcher |
JDK 1.4 added java.util.Pattern and Matcher to do regular expression matching. |
To write a constant string, put the characters between double quotes, eg "abc".
There are some characters that can't be written directly in a string. The backslash ('\') character preceeds any of these special characters. For example, if a string contains a double quotes, put a backslash ('\') in front of each internal double quote, eg "abc\"def\"ghi". The other most common escape character is the newline character, which is written as "n" following the backslash. For example, the following str