Posts

String in Java

Image
String: - String is a class in java and defined in java.lang package. It’s not a primitive data type like int and long. String class represents character Strings. String is immutable and final in java. It is sequence of characters or character Arrays.   String class implements Serializable, Comparable and CharSequence interfaces. CharSequence Interface The CharSequence interface is used to represent sequence of characters. It is implemented by String, StringBuffer and StringBuilder classes. It means, we can create string in java by using these 3 classes. The java String is immutable i.e. it cannot be changed. Whenever we change any string, a new instance is created. For mutable string, you can use StringBuffer and StringBuilder classes. How to create String Object? There is two ways to create String Object: 1-      By String literal 2-      By new keyword 1-     String literal:- Java String literal is created by using double quotes. Ex.: String str=”he