Created
June 24, 2011 13:34
-
-
Save sfussenegger/1044768 to your computer and use it in GitHub Desktop.
Stackoverflow: Single character String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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