// Checking out Java's String pool
// String pool used for constant expressions computed at compile time
import java.util.Scanner;
public class Str
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
String r = "first";
String s = "first";
System.out.println("r == s: " + (r == s)); // True
// Share a reference: Strings computed at compile time
String a = "first!!";
String b = "first" + "!!";
System.out.println("a == b: " + (a == b)); // True
// Share a reference: Strings computed at compile time
System.out.println("\"fir\" + \"st\" == b: " + ("fir" + "st!!" == b)); // True
String c = r + "!!";
System.out.println("b == c: " + (b == c)); // False
System.out.println("b .equals c: " + (b .equals (c))); // True
// Don't share a reference: Strings not computed at compile time
final String d = "first";
String e = d + "!!";
System.out.println("b == e: " + (b == e)); // True
// Share a reference: Strings computed at compile time
System.out.println( "Enter: ");
String in = scan.nextLine();
String f = d + in;
System.out.println("a == f: " + (a == f)); // False
System.out.println("a .equals f: " + (a .equals (f))); // True
// Don't share a reference: Strings not computed at compile time
}
}