🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.a == b
  2. B.a.equals(b)
  3. C.a.compare(b)
  4. 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 →