I have a list:
List<UserItem> userList = new ArrayList<>();
Where I add the following:
User father = new User();
father.setName("Peter");
UserItem parent = new UserItem(father, null);
userList.add(parent);
I then create another user:
User daughter = new User();
daughter.setName("Emma");
UserItem child = new UserItem(daughter, <OBJECT IN LIST WHERE NAME IS "PETER">);
userList.add(child);
However, I need to change the text wrapped in <>
above to the parent object I added before (the father), specified by the name ("Peter" in this case).
How can I find an object in a List by a specific attribute? In my case, how can I find the object in the List that has the name "Peter"?
Please note that I add hundreds, sometimes thousands, of different users like this to the list. Each "parent" has a unique name.