Klasse StreamUtil

java.lang.Object
org.teamapps.commons.util.StreamUtil

public class StreamUtil extends Object
  • Konstruktordetails

    • StreamUtil

      public StreamUtil()
  • Methodendetails

    • toLinkedHashMap

      public static <T, K, U> Collector<T,?,LinkedHashMap<K,U>> toLinkedHashMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper)
    • distinctByKey

      public static <T> Predicate<T> distinctByKey(Function<? super T,?> keyExtractor)
      Use with Stream.filter(Predicate).

      Example:

       
           record Person(String name) { }
           Stream.of(new Person("Joe"), new Person("Anna"), new Person("Joe"))
           		.filter(distinctByKey(Person::name))
           		.toList(); // Joe and Anna (each only once)