Skip to content

Instantly share code, notes, and snippets.

@TomTasche
Created May 4, 2013 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TomTasche/5518509 to your computer and use it in GitHub Desktop.
Save TomTasche/5518509 to your computer and use it in GitHub Desktop.
i had a discussion about the possible existence of a global "String pool" in newer versions of Java. turns out, there is no such thing. however, hardcoded strings are "pooled", i.e. String a and String b in the example are the *same instance of String*.
String a = "test";
String b = "test";
System.out.println("a == b? " + (a == b)); // true
String c = "tester";
String d = a + "er";
System.out.println("c == d? " + (c == d)); // false
@TomTasche
Copy link
Author

turns out, there IS a string pool after all. as i understand it, my test fails to prove its existence by design of the java developers.

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