Advertisement
String s = "Hello There";
String s = new String("Hello There");
String s = new String(); // line 1
s = "Hello There"; // line 2
Advertisement
//Initializing string in different ways.
public class String1
{
public static void main(String[] ar)
{
String str1 = new String("New York"); //First String object
String str2 = "New Delhi"; //Second String object
String str3 = new String(); //Third String object.
str3 = "London";
System.out.println("String 1 : "+str1);
System.out.println("String 2 : "+str2);
System.out.println("String 3 : "+str3);
String str4 = str1+str2; //addition of two String objects by + operator
System.out.println("String 4 : "+ str4);
}
String 1 : New York
String 2 : New Delhi
String 3 : London
String 4 : New YorkNew Delhi
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement