Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

filter and map multiple fields from java stream

// Note that you shouldn't normally use == on objects
Predicate<Detail> itemPredicate = d-> item.equals(d.getItem());
Predicate<Detail> namePredicate = d-> name.equals(d.getName());

details.stream()
    .filter(itemPredicate.and(namePredicate))
    .collect(Collectors.toList());
Comment

map multiple fields from java stream

private static <T> Predicate<T> distinctByKeys(Function<? super T, ?>... keyExtractors) 
{
  final Map<List<?>, Boolean> seen = new ConcurrentHashMap<>();
   
  return t -> 
  {
    final List<?> keys = Arrays.stream(keyExtractors)
                .map(ke -> ke.apply(t))
                .collect(Collectors.toList());
     
    return seen.putIfAbsent(keys, Boolean.TRUE) == null;
  };
}
Comment

PREVIOUS NEXT
Code Example
Java :: fibonacci series in java 
Java :: retrofit 
Java :: how to use ListIterator in java 
Java :: convertir string a char java 
Java :: how to convert line into string java 
Java :: thread java timer 
Java :: binary search java 
Java :: java arraylist with double 
Java :: java all characters in alphabet order simpler 
Java :: javafx fxmlloader location is not set 
Java :: Random Float in java 
Java :: how to empty list in java 
Java :: list of arrays java 
Java :: java array erstellen 
Java :: unchecked exception in java 
Java :: java protected keyword 
Java :: reading string after double in java 
Java :: java rgb to color 
Java :: copy linked list 
Java :: Java Create a BufferedOutputStream 
Java :: constructor 
Java :: int to char java 
Java :: nextint java 
Java :: startactivity not working in android adapter 
Java :: linked list vs vector 
Java :: java unique queue 
Java :: regex pattern for valid identifiers 
Java :: how to know if a file is iso-8859-1 encoded in java 
Java :: boolean operators in java 
Java :: Implement the static keyword – static variable, static block, static function and static class with following conditions 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =