list - How to apply contains function on attribute of a Java Object? -


i have address class as:

public class address{     private string city;     private string pincode;     private string state; } 

i have attribute of different object request private list<address> transitlocations.

how can check if transitlocations contains address having state equals "somestring" in 1 line.

ps: please assume getters & setters present in code.
don't want override equals because address class used @ other places too.

not being sure why solutions using filter , collect have been proposed...

you can use predicate , pass stream#anymatch

public boolean containsaddresswithstate(     collection<? extends address> collection, string state) {     return collection.stream().anymatch(a -> a.getstate().equals(state)); }     

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -