← Strings Quiz: all 8 questions
Strings Quiz · Question 2 of 8
In Java, how should you compare the contents of two strings a and b?
In Java, how should you compare the contents of two strings a and b?
- A.a == b
- B.a.equals(b)
- C.a.compare(b)
- D.a = b
Answer & explanation
Correct answer: a.equals(b)
== compares object references in Java; equals() compares the characters.
Can you get the rest right without peeking?
Take the timed Strings Quiz quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →