List of usage examples for java.util.stream Collectors groupingByConcurrent
public static <T, K> Collector<T, ?, ConcurrentMap<K, List<T>>> groupingByConcurrent( Function<? super T, ? extends K> classifier)
From source file:Main.java
public static void main(String[] args) { List<String> strings = new LinkedList<>(); strings.add("a"); strings.add("B"); strings.add("ab"); strings.add("abc"); strings.add("ABC"); ConcurrentMap<Integer, List<String>> byLength = strings.parallelStream() .collect(Collectors.groupingByConcurrent(String::length)); System.out.println(byLength); }
From source file:Main.java
public static void main(String[] args) { List<Person> roster = createRoster(); ConcurrentMap<Person.Sex, List<Person>> byGenderParallel = roster.parallelStream() .collect(Collectors.groupingByConcurrent(Person::getGender)); List<Map.Entry<Person.Sex, List<Person>>> byGenderList = new ArrayList<>(byGenderParallel.entrySet()); System.out.println("Group members by gender:"); byGenderList.stream().forEach(e -> { System.out.println("Gender: " + e.getKey()); e.getValue().stream().map(Person::getName).forEach(f -> System.out.println(f)); });/*from ww w . j av a2s.c om*/ }