What is the output of the following Kotlin code?
fun main() { val numbers = listOf(1, 2, 3, 4, 5) val doubled = numbers.map { it * 2 } println(doubled) }
Error
[1, 2, 3, 4, 5]
[2, 4, 6, 8, 10]
10
What is the most appropriate collection type in Kotlin to store a list of unique user IDs?
Map
List
MutableList
Set
Which method adds an element to a mutable list in Kotlin?
put()
add()
insert()
append()
Which method adds an element to the end of a mutable list in Kotlin?
push()
What is the correct way to print 'Hello, World!' to the console in Kotlin?
print("Hello, World!")
println("Hello, World!")
console.log("Hello, World!")
System.out.println("Hello, World!")
How do you read a line of input from the user in Kotlin?
input()
scanner.nextLine()
readLine()
read()
How do you declare a variable in Kotlin with a String value 'Hello'?
val greeting = "Hello"
string greeting = 'Hello'
var greeting = 'Hello'
var greeting: String = "Hello"
What is a field in Kotlin?
A static variable
A constant value
A property declared inside a function
A backing field for a property
fun main() { val result = add(3, 5) println(result) } fun add(a: Int, b: Int): Int = a + b
8
5
3
What is the primary difference between listOf() and mutableListOf() in Kotlin?
listOf()
mutableListOf()
listOf() creates a list of integers, while mutableListOf() creates a list of strings.
listOf() creates an immutable list, while mutableListOf() creates a mutable list.
listOf() creates a fixed-size list, while mutableListOf() creates a dynamically sized list.
There is no difference; both functions are interchangeable.