Example A:
String a = "hello" + " world!"; String b = "hello world!"; boolean compare = (a == b); // This return true
Example B:
a = "hello"; b = "hel" + "lo"; compare = (a == b); // This return true
Example C:
a = "Bye"; a += " bye!"; b = "Bye bye!"; compare = (a == b); // This return false
System.out.println(compare);
Correct is C, when the equals method is called, the content stored inside the String is analyzed. When the "==" is put it will always give false in case of Strings, because it is not of the primitive type.
upvoted 3 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
Vicky_65
3 months, 3 weeks agoakbiyik
8 months agocarloswork
8 months, 4 weeks agoiSnover
10 months ago