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<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5); Optional<Integer> sum = numbers.stream().reduce(Integer::sum); if (sum.isPresent()) { System.out.println(sum.get()); } else {//from w w w . ja va 2 s . co m System.out.println("noValue "); } }
From source file:Main.java
public static void main(String[] args) { List<Integer> numberList = Arrays.asList(1, 2, 3, 4, 5); Stream<Integer> listStream = numberList.stream(); System.out.println(Arrays.toString(listStream.toArray())); }
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<Integer> _numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); Object[] doubled = _numbers.stream().map(value -> value * 2).toArray(); System.out.println(Arrays.toString(doubled)); }
From source file:Main.java
public static void main(String[] args) { List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6); ///*from www. j a v a2 s . com*/ System.out.println(numbers.stream().filter(i -> i > 2).filter(i -> i % 2 == 0).mapToInt(i -> i * i) .findFirst().getAsInt()); }
From source file:Main.java
public static void main(String[] args) { List<String> stringList = Arrays.asList("2", "1", "3", "4"); Optional<String> m = stringList.stream().min(Comparator.reverseOrder()); if (m.isPresent()) { System.out.println(m.get()); } else {//w w w .ja v a2s . c o m System.out.println("No Value"); } }
From source file:Main.java
public static void main(String[] args) { List<String> stringList = Arrays.asList("2", "1", "3", "4"); Optional<String> m = stringList.stream().max(Comparator.reverseOrder()); if (m.isPresent()) { System.out.println(m.get()); } else {//w ww. ja v a2s. c o m System.out.println("No Value"); } }
From source file:Main.java
public static void main(final String[] args) { List<String> friends = Arrays.asList("Ross", "Chandler", "CSS", "Monica", "Joey", "Rachel"); friends.stream().map(name -> name.toUpperCase()).forEach(name -> System.out.print(name + " ")); }
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//www .jav a 2s. c o m .println(numbers.stream().map(number -> String.valueOf(number)).collect(Collectors.joining(", "))); }
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")); List<String> collect = s.filter(Objects::nonNull).collect(Collectors.toList()); System.out.println(collect);/*from w w w . j a va2 s . co m*/ }