Skip to content

Instantly share code, notes, and snippets.

@jskeet
Created August 1, 2018 10:47
Show Gist options
  • Save jskeet/fa8c6e035b752e9a339fc6ad4febda48 to your computer and use it in GitHub Desktop.
Save jskeet/fa8c6e035b752e9a339fc6ad4febda48 to your computer and use it in GitHub Desktop.
public class Test {
public static void main(String... args) {
String x = "abc";
String y = "def";
String xy = x + y;
String xyInterned = xy.intern();
System.out.println(xyInterned == xy);
// With this line here, the output is true, true
// which shows that the literal here is only taken
// from the string pool at the point of execution.
// If this line is moved to before the xy.intern()
// call, the result is false, false
String abcdef = "abcdef";
System.out.println(abcdef == xy);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment