Question: I have two ArrayLists of different size.

```
ArrayList<String> names = new ArrayList<String>();
ArrayList<User> users = new ArrayList<User>();

```

User is an Object with attributes name and address. I want to get the addresses where the names of the User object stored in ArrayList users is the same as the names stored in the ArrayList names.

Is this possible? If so, how?

Answer: 
You can use Java 8. 

Please try:

```
users.stream().filter(u -> names.contains(u.getName())).map(
                u -> "Name: " + u.getName() + ", address: " + u. getAddress()).forEach(System.out::println);

```
If you do loop over Users with `names.contains(..)` inside, you are doing a n^2 loop (approximately speaking).

I would put the users addresses into a map, keyed by name, then loop over the names list, pulling the addresses out of the map. Costs 2n (roughly) instead.