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

android - net_scheduler holding wakelock -

sql - MySQL : Getting Entries from a many-to-many table -

java - Retrieving data from database using jsp (Hibernate + Spring + Maven) -