List of usage examples for java.util List stream
default Stream<E> stream()
From source file:Main.java
public static void main(String[] args) { List<String> stringList = Arrays.asList("1.2", "2.2", "3", "4", "5"); stringList.stream().flatMapToLong(n -> LongStream.of(Long.parseLong(n))).forEach(System.out::println); }
From source file:Main.java
public static void main(String[] args) { List<String> stringList = Arrays.asList("1.2", "2.2", "3", "4", "5"); stringList.stream().mapToDouble(n -> Double.parseDouble(n)).filter(n -> n % 2 == 0) .forEach(System.out::println); }
From source file:Main.java
public static void main(String[] args) { List<String> stringList = Arrays.asList("1.2", "2.2", "3", "4", "5"); stringList.stream().flatMapToDouble(n -> DoubleStream.of(Double.parseDouble(n))) .forEach(System.out::println); }
From source file:Main.java
public static void main(String[] args) { List<String> stringList = Arrays.asList("2", "1", "3", "4"); long m = stringList.stream().collect(Collectors.counting()); System.out.println(m);//from ww w. jav a 2 s. c o m }
From source file:Main.java
public static void main(String[] args) { List<String> stringList = Arrays.asList("2", "1", "3", "4"); Object[] n = stringList.stream().toArray(); System.out.println(Arrays.toString(n)); }
From source file:Main.java
public static void main(String[] args) { List<Integer> l = Arrays.asList(4, 3, 5, 7, 2, 2, 3, 5); l.stream().reduce((a, b) -> a + b).ifPresent(System.out::println); l.parallelStream().reduce((a, b) -> a + b).ifPresent(System.out::println); System.out.println("isParallel list.stream(): " + l.stream().isParallel()); System.out.println("isParallel list.stream().parallel(): " + l.stream().parallel().isParallel()); System.out.println("isParallel list.parallelStream(): " + l.parallelStream().isParallel()); System.out.println(//w w w . j av a 2s . c o m "isParallel list.parallelStream().sequential(): " + l.parallelStream().sequential().isParallel()); }
From source file:Main.java
public static void main(String... args) { List<Integer> numbers = Arrays.asList(3, 4, 5, 1, 2); Optional<Integer> min = numbers.stream().reduce(Integer::min); min.ifPresent(System.out::println); }
From source file:Main.java
public static void main(String[] args) { List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5); Optional<Integer> o = numbers.stream().findAny(); if (o.isPresent()) { System.out.println(o.get()); } else {//from w ww .ja va2 s . co m System.out.println("no value"); } }
From source file:Main.java
public static void main(String[] args) { List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5); Optional<Integer> o = numbers.stream().findFirst(); if (o.isPresent()) { System.out.println(o.get()); } else {/* w ww .j a v a2 s . co m*/ System.out.println("no value"); } }
From source file:Main.java
public static void main(String[] args) throws Exception { // map//w w w . ja v a 2s. c om List<String> words = Arrays.asList("Hello", "World"); List<Integer> wordLengths = words.stream().map(String::length).collect(Collectors.toList()); System.out.println(wordLengths); }