PetkoTrenev

String equality

Jan 29th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. String s1 = "hello!";
  2. String s2 = "hello!";
  3. String s3 = "hello!".intern();
  4. String s4 = new String("hello!");
  5. String s5 = "lo";
  6.  
  7. System.out.println("s1 == s2 " + (s1 == s2)); // true
  8. System.out.println("s1 == s3 " + (s1 == s3)); // true
  9. System.out.println("s1 == s4 " + (s1 == s4)); // false
  10. System.out.println("s1 == s4.intern() " + (s1 == s4.intern())); // true
  11. System.out.println("s1 == \"hel\" + \"lo!\": " + (s1 == "hel" + "lo!")); // true
  12. System.out.println("s1 == \"hel\" + s5: " + (s1 == "hel" + s5)); // false
Advertisement
Add Comment
Please, Sign In to add comment