s1 is a string literal stored in the string pool.
s2 is created with new, so it's a new object in heap memory.
java
Copy
Edit
System.out.print(s1.equals(s2) + " ");
equals() compares content.
"foo-bar".equals("foo-bar") → ✅ returns true
java
Copy
Edit
System.out.print(s1 == s2);
== compares references (memory addresses).
s1 and s2 are different objects → ❌ returns false
java
Copy
Edit
System.out.print(" " + s1.compareTo(s2));
compareTo() compares strings lexicographically.
Both strings are exactly the same → returns 0
upvoted 1 times
...
This section is not available anymore. Please use the main Exam Page.1z0-811 Exam Questions
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.
ahmed_alshehhi
2 months, 2 weeks ago