Given the following code:
What is the result?
String.equals() compares the character contents of strings, so str1.equals(str3) is true because both contain Java. The == operator compares object references; str3 is created through runtime concatenation and is not the same object as the str1 literal, so that comparison is false.
String.equals()
str1.equals(str3)
true
Java
==
str3
str1
false
Community Discussion