Skip to content

Instantly share code, notes, and snippets.

@sfussenegger
Created June 24, 2011 13:34
Show Gist options
  • Save sfussenegger/1044768 to your computer and use it in GitHub Desktop.
Save sfussenegger/1044768 to your computer and use it in GitHub Desktop.
Stackoverflow: Single character String
public class StringLiterals {
public static void main(String[] args) {
String s1 = "abc"; // interned by default
String s2 = new String(new char[] {'a', 'b', 'c'}); // no chance to intern here
System.out.println(s1 == s2); // false
System.out.println(s1 == s2.intern()); // true - uses interned s1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment