How to retrieve similar values inside of object that inside ArrayList of objects.
public class People{ private String name; private String email; private String accountnum; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getAccountnum() { return accountnum; } public void setAccountnum(String accountnum) { this.accountnum= accountnum; } public People(String name, String email, String accountnum) { this.name = name; this.email = email; this.accountnum= accountnum; } } I have a ArrayList of objects that created from this class People peop1 = new People("john", "john@gmail.com", "56hk"); People peop2 = new People("Rose", "rose@gmail.com", "5689hk"); People peop3 = new People("john", "john@gmail.com", "5676hk"); List<People> peoplelist = new ArrayList<People>(); peoplelist .add(peop1); peoplelist.add(peop2 ); peoplelist .add(peop3 ); What i want to do is to retrieve the email and its accountnums. like this john@gmail.com = {56hk,5676hk} I know i can loop through and return a map or something like that. Are there any other way to do that?