Created
April 23, 2012 18:31
-
-
Save lukaspili/2472910 to your computer and use it in GitHub Desktop.
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 StringImmuabilityTraining { | |
public static void main(String[] args) { | |
// String are immuable | |
String foo = "John"; | |
String foo2 = foo; | |
foo += "Toto"; | |
System.out.println(foo); // "JohnToto" | |
System.out.println(foo2); // "John" | |
// StringBuilder are muable | |
StringBuilder sb = new StringBuilder("John"); | |
StringBuilder sb2 = sb; | |
sb.append("Toto"); | |
System.out.println(sb2); // "JohnToto" | |
System.out.println(sb2); // "JohnToto" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment