0
0
Kotlinprogramming~10 mins

Equality (== structural vs === referential) in Kotlin - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if two strings have the same content using structural equality.

Kotlin
val a = "hello"
val b = "hello"
println(a [1] b)
Drag options to blanks, or click blank then click option'
Aequals
B===
C!=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using === instead of == for content comparison.
2fill in blank
medium

Complete the code to check if two string variables point to the exact same object using referential equality.

Kotlin
val x = "world"
val y = x
println(x [1] y)
Drag options to blanks, or click blank then click option'
A===
B==
Cequals
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using == instead of === to check reference equality.
3fill in blank
hard

Fix the error in the code to correctly compare two different String objects for content equality.

Kotlin
val s1 = String(charArrayOf('k', 'o', 't', 'l', 'i', 'n'))
val s2 = String(charArrayOf('k', 'o', 't', 'l', 'i', 'n'))
println(s1 [1] s2)
Drag options to blanks, or click blank then click option'
A===
Bequals()
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using === instead of == for content comparison.
4fill in blank
hard

Fill both blanks to create a map of words to their lengths, but only include words with length greater than 3.

Kotlin
val words = listOf("cat", "kotlin", "dog", "java")
val lengths = words.associateWith { it.[1] }
val filtered = lengths.filter { it.value [2] 3 }
Drag options to blanks, or click blank then click option'
Alength
B>
C<
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of > in the filter condition.
5fill in blank
hard

Fill all three blanks to create a map of uppercase words to their lengths, including only words with length greater than 3.

Kotlin
val words = listOf("apple", "bat", "carrot", "dog")
val result = words.associate { it.[1]() to it.[2] }
val filtered = result.filter { it.value [3] 3 }
Drag options to blanks, or click blank then click option'
Auppercase
Blength
C>
DtoUpperCase
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'uppercase' property instead of 'toUpperCase()' function.