String
String is an object that represents sequence of char. String is immutable in Java
Creating String Object:
Method 1: (Using String literal)
char[] ch = {'v','i','c','k','y'};
String s = new String(ch);
Method 2: (Using new keyword)
String s = new String("Vicky");
Method 3: (Using String literal)
String s = "Vicky";
Methods in String
concat(), split(), length(), substring()
String Pool
String is special class in java. String Pool in java is a pool of Strings stored in Java Heap Memory. We can create String object using new operator as well as providing values in double quotes.
String s1 = "Vicky";
String s2 = "Vicky";
if(s1 == s2)
System.out.println("Equal"); //Prints equal.
String s3 = new String("Vicky");
String s4 = new String("Vicky");
if(s3 == s4)
System.out.println("Equal");
else
System.out.println("Not Equal"); //Prints Not Equal