Compare two different objects in different lists in Java

I need to check if an object present in list A exists in list B without using nested for loops because if the lists have a large size, it takes too much time.

This is my code :

for(Person el : persons)
    for(Client in : clients)
        if(el.getIdentifier() == in.getTire().getIdentifier())

How can i achieve the same result without using loops and break?


This will change the complexity of your code from O(NxM) to O(N+M):

    Set<Integer> personIds =
            .map(e -> e.getIdentifier())

    boolean exists =
            c -> personIds.contains(c.getTire().getIdentifier()));