Java String is an Object that represents the sequence of characters. All String literals used in the Java programs like “Hello” or “World” are implemented as String objects.

String in Java is immutable. That means the value of the String object cannot be changed once it is created. When you try to alter the value of the String object, a new object is created and assigned back to the reference. StringBuffer and StringBuilder classes support mutable strings.

There are two ways to create a String object in Java. You can either assign a String literal to the String reference like,

String str = "abc";

or you can use new keyword to create a String object like,

String str = new String("abc");

Java String class is declared as a final class, so you cannot extend it. String class implements CharSequence interface which represents sequence of characters. StringBuffer and StringBuilder classes also implement the CharSequence interface. String class also implements Comparable and Serializable interface to allow string objects to be compared with one another and save/load state respectively.

The String class provides various methods to searching strings, extracting substrings, split it in various chunks and concatenating them. Below given are Java String examples which will talk about these String methods in details.

Java String Examples