Wednesday, December 2, 2015

What is the difference between "String Literal" and "String Object"





package com.javaninja.stringexamples;

public class StringExample1 {
   //Difference between "String Literal" and "String Object"
public static void main (String args[])
{
String str1 = "Java";
String str2 = "Java";

System.out.println("Is str1==str2 ? " +( str1==str2)); //Prints true

String str3 = new String("Java");

System.out.println("Is str1==str3 ? " +( str1==str3)); //Prints false

}
}




No comments: