Answers for "java get single element from list that contains 2 elements"

2

java find item in list by property

Customer james = customers.stream()
  .filter(customer -> "James".equals(customer.getName()))
  .findAny()
  .orElse(null);
Posted by: Guest on February-19-2020
0

java find if element of list in present in another list

list1.stream()
   .map(Object1::getProperty)
   .anyMatch(
     list2.stream()
       .map(Object2::getProperty)
       .collect(toSet())
       ::contains)

// Example with predicate
Predicate<Object> notInList1 = object -> list1.stream().noneMatch(object::equals);
List<Object> missingInList1 = list2.stream().filter(notInList1).collect(Collectors.toList());
Posted by: Guest on February-26-2020

Code answers related to "java get single element from list that contains 2 elements"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language