Skip to content

Instantly share code, notes, and snippets.

@agustarc
Created December 21, 2016 17:48
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 agustarc/abf35cfc7be059b4c1d2756da62224df to your computer and use it in GitHub Desktop.
Save agustarc/abf35cfc7be059b4c1d2756da62224df to your computer and use it in GitHub Desktop.
public class StringMemoryIntern {
public static void main(String... args) {
String literal = "loper";
String object = new String("loper");
String intern = object.intern();
System.out.println(literal == object); // false
System.out.println(literal.equals(object)); // true
System.out.println(literal == intern); // true
System.out.println(literal.equals(intern)); // true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment