Java String Type

Java String Type

String Type In Java
As we have already studied string is not a data type in Java instead String is a class that is found inside java.lang package which is automatically imported means we do not need to import the package explicitly.
String is a collection, or sequence of characters like “Ram”, “10/A”, etc.
String must be enclosed in double quotes.
In Java, String is a class, hence the first letter will be in upper case.
As String is a class the first latter of String literal will always be written in Upper case and the rest of it in a  small case.
Now we will see Examples - 
Example  -
// Demonstrating Strings.

class StringDemo 

public static void main(String args[]) 
String strOb1 = "First String";
String strOb2 = "Second String";
String strOb3 = strOb1 + " and " + strOb2;

Output  - 
First String

Second String

First String and Second String
Example -
// Demonstrating some String methods.

class StringDemo2 {
public static void main(String args[]) {
String strOb1 = "First String";
String strOb2 = "Second String";
String strOb3 = strOb1;
System.out.println("Length of strOb1: " +
System.out.println("Char at index 3 in strOb1: " +
System.out.println("strOb1 == strOb2");
System.out.println("strOb1 != strOb2");
System.out.println("strOb1 == strOb3");
System.out.println("strOb1 != strOb3");
Output - 
Length of strOb1: 12
Char at index 3 in strOb1: s
strOb1 != strOb2
strOb1 == strOb3