To check if two lists are equal in Kotlin, you can use the equals
method or the ==
operator.
In this example,
list1
and list2
with initial values.equals
method to check if list1
equals list2
.fun main() {
val list1 = listOf(1, 2, 3)
val list2 = listOf(1, 2, 3)
val result = list1.equals(list2)
println("Are the lists equal? $result")
}
Are the lists equal? true
In this example,
list1
and list2
with initial values.==
operator to check if list1
equals list2
.fun main() {
val list1 = listOf(1, 2, 3)
val list2 = listOf(1, 2, 3)
val result = list1 == list2
println("Are the lists equal? $result")
}
Are the lists equal? true
In this tutorial, we learned How to check if Two Lists are Equal in Kotlin language with well detailed examples.