0
0
Kotlinprogramming~10 mins

Why Java interop matters in Kotlin - Test Your Understanding

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

Complete the code to create a Java ArrayList in Kotlin.

Kotlin
val list = [1]<String>()
Drag options to blanks, or click blank then click option'
AList
BArrayList
CMutableList
DSet
Attempts:
3 left
💡 Hint
Common Mistakes
Using Kotlin's List which is immutable by default.
Using Set which is a different collection type.
2fill in blank
medium

Complete the code to call a Java method from Kotlin.

Kotlin
val result = javaObject.[1]()
Drag options to blanks, or click blank then click option'
AtoString
Binvoke
CjavaMethod
Dcall
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names that don't exist on the Java object.
Trying to call Kotlin-specific functions on Java objects.
3fill in blank
hard

Fix the error in calling a Java static method from Kotlin.

Kotlin
val max = Math.[1](5, 10)
Drag options to blanks, or click blank then click option'
AmaxValue
Bmaximum
CmaxOf
Dmax
Attempts:
3 left
💡 Hint
Common Mistakes
Using Kotlin's maxOf instead of Java's Math.max.
Using incorrect method names that don't exist.
4fill in blank
hard

Fill both blanks to create a Java HashMap and add an entry in Kotlin.

Kotlin
val map = [1]<String, Int>()
map.[2]("key", 1)
Drag options to blanks, or click blank then click option'
AHashMap
Bput
Cadd
DMutableMap
Attempts:
3 left
💡 Hint
Common Mistakes
Using Kotlin's MutableMap instead of Java's HashMap.
Using add instead of put to add entries.
5fill in blank
hard

Fill all three blanks to iterate over a Java ArrayList in Kotlin and print each item.

Kotlin
val list = [1]<String>()
list.add("apple")
for ([2] in list) {
    println([3])
}
Drag options to blanks, or click blank then click option'
AArrayList
Bitem
DMutableList
Attempts:
3 left
💡 Hint
Common Mistakes
Using Kotlin's MutableList instead of Java's ArrayList.
Using different variable names inconsistently.