Question: I have an `ArrayList<UIToto>`, each `UIToto` contains 

```
(String id, String name, String info)

```

For example 

```
(4546-fdsf4545sfd-dfs545, titi, female)
(dqs4d65q4-45d4s54545sfd-dfss54545, tutu, male)

```

I have a list of ids like 

```
String ids = "dqs4d65q4-45d4s54545sfd-dfss54545, 4545-dsqd45-dqs,4d5s44-ss4-dqsd";

```

For each ids, I retrieve the id and I want to get the UIToto in my ArrayList:

```
ArrayList<UIToto> totoList = retrieveTotoList();
String[] ids = "dqs4d65q4-45d4s54545sfd-dfss54545, 4545-dsqd45-dqs,4d5s44-ss4-dqsd";
for(int i=0; i <= ids.length; i++) {
    System.out.println(("id = " + ids[i]);
    //don't work because it's not the index but the id ...
UIToto response = totoList.get(Integer.parseInt(ids[1]));
System.out.println("response = " + response);
 }

```

Is it possible?

Thanks!

Answer: 
Try 

```
ArrayList<UIToto> totoList = retrieveTotoList;
ArrayList<UIToto> resultList= new ArrayList<UIToto>();

String[] ids = {"dqs4d65q4-45d4s54545sfd-dfss54545", 
                "4545-dsqd45-dqs,4d5s44-ss4-dqsd"}; 

for(int i = 0; i < ids.length; i++) {
    for(UIToto uIToto : totoList) {
        if(uIToto.getId().equals(ids[i])) {
            resultList.add(uIToto);     
        }
    }
}

```
Depending on your usecase, a Map with the string-id as key might be more elegant then an arrayList when you need to find an object in a collection based on one of the object's values.

```
public static void main(String argv) {
    Map<String, UIToto> totoMap = getTotoMap();
    String[] ids = {"dqs4d65q4-45d4s54545sfd-dfss54545", "4545-dsqd45-dqs,4d5s44-ss4-dqsd"};
    for(int i=0; i <= ids.length; i++) {
        System.out.println(("id = " + ids[i]));

        UIToto response = totoMap.get(ids[i]);
        System.out.println("response = " + response);
    }
}

//Example how to Construct the map with the String as ID. 
//Ideally the map would be constructed without first creating the list
public Map<String,UIToto> getTotoMap() {
    Map<String, UIToto> totoMap = new HashMap<String, UIToto>();
    List<UIToto> totoList = retrieveTotoList();
    for (UIToto uiToto :totoList) {
        totoMap.put(uiToto.getId(), uiToto);
    }
}

```