check if a list contains an object java code example
Example 1: check if a list contains a string java
String search = "A";
for(String str: myList) {
if(str.trim().contains(search))
return true;
}
return false;
Example 2: java list contains object with property
boolean found = list.stream()
.anyMatch(p -> p.name.equals(personName));