Skip to content

Instantly share code, notes, and snippets.

@jskeet
Created August 1, 2018 10:53
Show Gist options
  • Save jskeet/eaf4ede0979fbe66dcf06fe9dcabd573 to your computer and use it in GitHub Desktop.
Save jskeet/eaf4ede0979fbe66dcf06fe9dcabd573 to your computer and use it in GitHub Desktop.
public class Test {
public static void main(String... args) {
String x = new String(new char[] {'a', 'b', 'c'});
String y = new String(new char[] {'d', 'e', 'f'});
String xy = x + y;
xy.intern();
// With this line here, the output is 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
String abcdef = "abcdef";
System.out.println(abcdef == xy);
}
}
@abranhe
Copy link

abranhe commented Sep 5, 2018

Why don't you add the file extension instead of .txt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment