String variable declaration: – In java, strings are class object and implemented using two classes namely String and StringBuffer. A java string is an object of the String class. Java string, as compare to C strings, are more reliable and predictable. A java string is not a character array and is not null terminated. Syntax of string declaration is –

String <String Name>;
<String Name>=new String(“String”);

For example –

String FirstName;
FirstName=new String(“Vivek”);

Here, string class declared with an object first name and it initialize value of string as Vivek.

Advertisements