To check if a List is empty in Kotlin, you can use the isEmpty() method of the List class.
In this example,
myList
.isEmpty()
method of the List object myList
to check if it is empty.isEmpty()
method returns true if the list is empty, false otherwise.fun main() {
val myList = listOf<Int>()
val empty = myList.isEmpty()
println("Is list empty: $empty")
}
Is list empty: true
In this example,
myList
.isEmpty()
method of the List object myList
to check if it is empty.isEmpty()
method returns true if the list is empty, false otherwise.fun main() {
val myList = listOf(1, 2, 3, 4, 5)
val empty = myList.isEmpty()
println("Is list empty: $empty")
}
Is list empty: false
In this tutorial, we learned How to check if a List is Empty in Kotlin language with well detailed examples.