Stream group Joining - Java Lambda Stream

Java examples for Lambda Stream:Collector

Description

Stream group Joining

Demo Code



//package com.book2s;

import java.util.Collection;
import java.util.HashMap;
import java.util.function.Function;
import java.util.stream.Collectors;

public class Main {
  public static <T, K, V> HashMap<K, String> groupJoining(Collection<T> entities, Function<T, K> keyMapper,
      Function<T, String> valueMapper, String delimiter) {
    return entities.stream().collect(
        Collectors.groupingBy(keyMapper, HashMap::new, Collectors.mapping(valueMapper, Collectors.joining(delimiter))));
  }/* w ww.  ja  v  a2  s. c om*/
}

Related Tutorials