Good day, i\'m stuck figuring out how to get a single object from a list, i did google but all the topics show how to return a List
with sorted objects or somet
You can use this extension function also which return pair Pair(Boolean,T)
e.g
val id=2
val item= myList.customContains{it-> it.userId ==id}
if(item.first){
item.second //your object
// your code here
}else{
// if item no present
}
fun List.customContains(function: (currentItem: E) -> Boolean): Pair {
for (current in 0 until this.size) {
if (function(this[current])) {
return Pair(true, this[current])
}
}
return Pair(false, null)
}