junaid
mutability/immutability, array deep copy & shallow copyunknown
kotlin
2 years ago
1.1 kB
1
Indexable
Never
class SOSContact () { public var name: String? = null public var number: String? = null public var contactDataId: String? = null } fun main() { val testList1 = mutableListOf( SOSContact().apply { contactDataId="1" name="1" number="1" }) val testList2 = mutableListOf( SOSContact().apply { contactDataId="1" name="1" number="1" }) println(testList1 == testList2) println(isContactListEqual(testList1, testList2)) } fun isContactListEqual( first: List<SOSContact>, second: List<SOSContact> ): Boolean { if (first.size != second.size) { return false } first.forEachIndexed { index, value -> val isSameItem = when { second[index].name != value.name -> false second[index].number != value.number -> false second[index].contactDataId != value.contactDataId -> false else -> true } if(!isSameItem) return false } return true }