Example usage for java.util.stream Collectors joining

List of usage examples for java.util.stream Collectors joining

Introduction

In this page you can find the example usage for java.util.stream Collectors joining.

Prototype

public static Collector<CharSequence, ?, String> joining(CharSequence delimiter) 

Source Link

Document

Returns a Collector that concatenates the input elements, separated by the specified delimiter, in encounter order.

Usage

From source file:Main.java

public static void main(String[] args) {
    Stream<String> s = Stream.of("a", "b", "c");

    String names = s.collect(Collectors.joining(", "));

    System.out.println(names);/* w  ww  .  j  a v a  2 s  . c  o  m*/
}

From source file:Main.java

public static void main(String... args) {
    String n = Food.menu.stream().map(Food::getName).collect(Collectors.joining(", "));
    System.out.println(n);//from w ww.  j a va2s .co  m

}

From source file:Main.java

public static void main(String[] args) {
    // collect as typed array
    Stream<String> words = Stream.of("All", "men", "are", "created", "equal");
    final String joinedWords = words.collect(Collectors.joining(" "));
    System.out.println(joinedWords);

}

From source file:Main.java

public static void main(String[] argv) {
    List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7);

    System.out//  w ww . ja v  a  2s  .  c  om
            .println(numbers.stream().map(number -> String.valueOf(number)).collect(Collectors.joining(", ")));
}

From source file:Main.java

public static void main(String[] args) {
    String names = Employee.persons().stream().filter(Employee::isMale).map(Employee::getName)
            .collect(Collectors.joining(", "));
    System.out.println(names);/* w ww .  j  av  a  2 s.c o m*/

    names = Employee.persons().parallelStream().filter(Employee::isMale).map(Employee::getName)
            .collect(Collectors.joining(", "));
    System.out.println(names);

}

From source file:Main.java

public static void main(String[] args) {

    List<String> names = Arrays.asList("CSS", "CSS3", "HTML", "Java", "Javascript", "Oracle", "MySQL");

    String name5 = names.stream().map(Main::toUpperCase).filter(Main::greaterThanFive).limit(2)
            .collect(Collectors.joining(" + ")).toString() + " = WSM!!!";

    System.out.println(name5);//w ww.j ava2  s  .c o m
}

From source file:Main.java

public static void main(String[] args) {
    Map<Employee.Gender, String> namesByGender = Employee.persons().stream().collect(Collectors
            .groupingBy(Employee::getGender, Collectors.mapping(Employee::getName, Collectors.joining(", "))));
    System.out.println(namesByGender);
}

From source file:Main.java

public static void main(String[] args) {
    Map<Boolean, String> partionedByMaleGender = Employee.persons().stream().collect(Collectors
            .partitioningBy(Employee::isMale, Collectors.mapping(Employee::getName, Collectors.joining(", "))));
    System.out.println(partionedByMaleGender);
}

From source file:Main.java

public static void main(String[] args) {
    Map<Employee.Gender, String> namesByGender = Employee.persons().stream()
            .collect(Collectors.groupingByConcurrent(Employee::getGender,
                    Collectors.mapping(Employee::getName, Collectors.joining(", "))));
    System.out.println(namesByGender);
}

From source file:Main.java

public static void main(String[] args) {
    Map personsByGenderAndDobMonth = Employee.persons().stream().collect(
            Collectors.groupingBy(Employee::getGender, Collectors.groupingBy(p -> p.getDob().getMonth(),
                    Collectors.mapping(Employee::getName, Collectors.joining(", ")))));

    System.out.println(personsByGenderAndDobMonth);
}