Casting
Casting
Casting
Java String contains an immutable sequence of Unicode characters. Java String is differ from string
in C or C++, where (in C or C++) string is simply an array of char. String class is encapsulated
under java.lang package.
The Java String is immutable which means it cannot be changed. Whenever we change any string, a
new instance is created. For mutable strings, you can use StringBuffer and StringBuilder classes
Java String class provides a lot of methods to perform operations on string such as compare(),
concat(), equals(), split(), length(), replace(), compareTo(), intern(), substring() etc.
The java.lang.String class implements Serializable, Comparable and CharSequence interfaces.
CharSequence Interface
The CharSequence interface is used to represent the sequence of characters. String, StringBuffer and
StringBuilder classes implement it. It means, we can create strings in java by using these three
classes.
The Java String is immutable which means it cannot be changed. Whenever we change any string, a
new instance is created. For mutable strings, you can use StringBuffer and StringBuilder classes.
String s="welcome"; // String Literal
String s1="Welcome";
String s2="Welcome";//It doesn't create a new instance