Advertisement
Guest User

Untitled

a guest
May 25th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. // These two have the same value
  2. new String("test").equals("test") ==> true
  3.  
  4. // ... but they are not the same object
  5. new String("test") == "test" ==> false
  6.  
  7. // ... neither are these
  8. new String("test") == new String("test") ==> false
  9.  
  10. // ... but these are because literals are interned by
  11. // the compiler and thus refer to the same object
  12. "test" == "test" ==> true
  13.  
  14. // concatenation of string literals happens at compile time resulting in same objects
  15. "test" == "te" + "st" ==> true
  16.  
  17. // but .substring() is invoked at runtime, generating distinct objects
  18. "test" == "!test".substring(1) ==> false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement