Recall & Review
beginner
What does the
equals() function do when comparing two strings in Kotlin?The
equals() function checks if two strings have exactly the same characters in the same order. It returns true if they are equal, otherwise false.Click to reveal answer
beginner
How does
compareTo() work when comparing two strings?The
compareTo() function compares two strings lexicographically (like dictionary order). It returns a negative number if the first string is less, zero if they are equal, and a positive number if the first string is greater.Click to reveal answer
intermediate
What is the difference between
== and equals() when comparing strings in Kotlin?In Kotlin,
== checks structural equality and calls equals() under the hood for strings. So, == and equals() behave the same for string content comparison.Click to reveal answer
beginner
What does a
compareTo() result of zero mean?A
compareTo() result of zero means the two strings are exactly equal in content and order.Click to reveal answer
beginner
If
str1.compareTo(str2) returns a positive number, what does it tell you about str1 and str2?It means
str1 comes after str2 in dictionary order. So, str1 is 'greater' than str2.Click to reveal answer
What does
"apple".equals("Apple") return in Kotlin?✗ Incorrect
The
equals() function is case-sensitive, so "apple" is not equal to "Apple".What will
"cat".compareTo("car") return?✗ Incorrect
Since 't' comes after 'r' in the alphabet, "cat" is greater than "car", so compareTo returns a positive number.
Which operator in Kotlin calls
equals() when comparing strings?✗ Incorrect
The
== operator checks structural equality and calls equals() for strings.If
str1.compareTo(str2) returns 0, what can you say about str1 and str2?✗ Incorrect
A zero result means the two strings are exactly equal.
Which method would you use to check if two strings have the same content in Kotlin?
✗ Incorrect
The
equals() method checks if two strings have the same content.Explain how
equals() and compareTo() differ when comparing strings in Kotlin.Think about equality vs order.
You got /4 concepts.
Describe what the result of
compareTo() tells you about two strings.Imagine comparing words in a dictionary.
You got /4 concepts.