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 something similar.
I have a User Class
class User() {
var email: String = ""
var firstname: String = ""
var lastname: String = ""
var password: String = ""
var image: String = ""
var userId: String = ""
constructor(email:String,
firstname: String,
lastname: String,
password: String,
image: String, userId : String) : this() {
this.email = email
this.firstname = firstname
this.lastname = lastname
this.password = password
this.image = image
this.userId = userId
}
}
In java i would write something like
User getUserById(String id) {
User user = null;
for(int i = 0; i < myList.size;i++;) {
if(id == myList.get(i).getUserId())
user = myList.get(i)
}
return user;
}
How can i achieve the same result in kotlin?