Example usage for java.util.stream Collectors toList

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

Introduction

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

Prototype

public static <T> Collector<T, ?, List<T>> toList() 

Source Link

Document

Returns a Collector that accumulates the input elements into a new List .

Usage

From source file:Main.java

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

    List<String> names = s.collect(Collectors.toList());

    System.out.println(names);//from   w w  w. jav  a 2 s.  c  om
}

From source file:Main.java

public static void main(String[] args) {
    Integer[] numbers = { 1, 2, 3, 4 };
    Stream<Integer> arrayStreams2 = Arrays.stream(numbers);

    System.out.println(arrayStreams2.collect(Collectors.toList()));

}

From source file:Main.java

public static void main(String[] args) {
    List<String> names = Employee.persons().stream().map(Employee::getName).collect(Collectors.toList());
    System.out.println(names);/*from w ww  . j a  v  a2 s  .c  o m*/

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    // map/*from  www  .  j  a  v a 2 s. co m*/
    List<String> words = Arrays.asList("Hello", "World");
    List<Integer> wordLengths = words.stream().map(String::length).collect(Collectors.toList());
    System.out.println(wordLengths);

}

From source file:Main.java

public static void main(String[] args) {
    List<String> _names = Arrays.asList("Bob", "Tom", "Jeff", "Scott", "Jennifer", "Steve");

    List<String> greetings = _names.stream().map(name -> "Hello " + name).collect(Collectors.toList());
    System.out.println(greetings);

}

From source file:Main.java

public static void main(String args[]) {
    List<Person> people = Arrays.asList(new Person("B", 25, "Main Street"), new Person("A", 27, "Off Street"));
    List<String> listNames = people.stream().map(u -> u.getName()).collect(Collectors.toList());
    System.out.println(listNames);
}

From source file:Main.java

public static void main(String[] args) {
    List<Trade> trades = TradeUtil.createTrades();

    List<Integer> list = trades.stream().map(t -> t.getQuantity()).collect(Collectors.toList());
    System.out.println("Collect List: " + list);
}

From source file:Main.java

public static void main(String[] args) {
    List<String> names = Arrays.asList("Chris", "HTML", "XML", "CSS");

    Stream<String> s = names.stream().filter(name -> name.startsWith("C"));

    System.out.println(s.collect(Collectors.toList()));
}

From source file:Main.java

public static void main(String[] args) {
    List<String> names = Employee.persons().stream().map(Employee::getName).collect(
            Collectors.collectingAndThen(Collectors.toList(), result -> Collections.unmodifiableList(result)));
    System.out.println(names);//from   w  w w  .j  a  va 2 s  . c  o m
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    List<String> argList = Arrays.asList("help", "v");

    Predicate<String> isHelp = (s) -> s.matches("(h|help)");

    argList = argList.stream().filter(isHelp.negate()).collect(Collectors.toList());

    System.out.println(argList);/* ww  w  .ja v a  2 s  . c  om*/
}