String a = "Java";
String b = "Java";
System.out.println(a == b);  // True
// When you declare string like this, you are actually calling intern() method on String. 
// This method references internal pool of string objects.
// If there already exists a string value “Java”, 
// then str will reference of that string and no new String object will be created

String c = new String("Java");
String d = new String("Java");
System.out.println(c == d);  // False
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter