Recall & Review
beginner
What does the
== operator check when used with strings in Java?The
== operator checks if two string variables point to the exact same object in memory, not if their text content is the same.touch_appClick to reveal answer
beginner
How do you correctly compare the content of two strings in Java?
Use the
equals() method, like string1.equals(string2), to check if two strings have the same characters in the same order.touch_appClick to reveal answer
intermediate
What is the difference between
equals() and equalsIgnoreCase() methods in Java strings?equals() compares strings considering uppercase and lowercase letters, while equalsIgnoreCase() ignores case differences when comparing.touch_appClick to reveal answer
intermediate
What does the
compareTo() method return when comparing two strings?It returns an integer: zero if strings are equal, a negative number if the first string is lexicographically less, and a positive number if it is greater.
touch_appClick to reveal answer
beginner
Why should you avoid using
== for string content comparison in Java?Because
== checks if two references point to the same object, not if their text is the same. This can lead to wrong results when strings have the same content but are different objects.touch_appClick to reveal answer
Which method correctly compares the text content of two strings in Java?
What does
string1 == string2 check in Java?What will
"Hello".equalsIgnoreCase("hello") return?If
string1.compareTo(string2) returns a negative number, what does it mean?Which is the best way to compare two strings ignoring case?
Explain how to compare two strings in Java to check if they have the same text.
Describe what the compareTo() method does when comparing two strings.
