How do you declare a variable in Kotlin with a String value 'Hello'?
var greeting: String = "Hello"
val greeting = "Hello"
string greeting = 'Hello'
var greeting = 'Hello'
What is the output of the following code?
for (i in 1..5) { if (i == 3) continue println(i) }
1245
12345
1234
124
Which data structure is best suited for storing a collection of unique elements in Kotlin?
List
Map
Array
Set
What is the most appropriate collection type in Kotlin to store a list of unique user IDs?
MutableList
How do you define a property in Kotlin?
Using 'field' keyword
Properties are automatically generated from constructor parameters
Using 'var' or 'val' keyword before the variable declaration
Using 'property' keyword
What will be printed after executing the following Kotlin code?
for (i in 1..3) { println(i * 2) }
2 4 6
1 2 3
123
246
How do you create an immutable map with key-value pairs in Kotlin?
dictionaryOf("key1" to "value1", "key2" to "value2")
mapOf("key1" to "value1", "key2" to "value2")
hashMapOf("key1" to "value1", "key2" to "value2")
mutableMapOf("key1" to "value1", "key2" to "value2")
What is the primary difference between listOf() and mutableListOf() in Kotlin?
listOf()
mutableListOf()
There is no difference; both functions are interchangeable.
listOf() creates a list of integers, while mutableListOf() creates a list of strings.
listOf() creates a fixed-size list, while mutableListOf() creates a dynamically sized list.
listOf() creates an immutable list, while mutableListOf() creates a mutable list.
What is the primary advantage of using arrays over lists in Kotlin?
Arrays are dynamically sized.
Arrays are immutable.
Arrays can store different data types.
Arrays offer better performance for certain operations.
How do you access the value associated with the key "name" in a Kotlin map named user?
user
user.get("name")
user.name
user.getValue("name")
user["name"]