List of usage examples for java.util Arrays stream
public static DoubleStream stream(double[] array)
From source file:Main.java
public static void main(String[] args) throws Exception { Arrays.stream(new int[] { 1, 2, 3 }).map(n -> 2 * n + 1).average().ifPresent(System.out::println); }
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(Arrays.toString(arrayStreams2.toArray())); }
From source file:Main.java
public static void main(String[] args) { int[] numbers = { 2, 3, 5, 7, 11, 13 }; IntStream intStream = Arrays.stream(numbers); intStream = intStream.limit(3);//from w w w .j av a 2 s . com System.out.println(intStream.sum()); }
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) throws Exception { // map/*w ww. ja v a 2 s .c o m*/ List<String> words = Arrays.asList("Hello", "World"); words.stream().flatMap((String line) -> Arrays.stream(line.split(""))).distinct() .forEach(System.out::println); }
From source file:Main.java
public static void main(String[] argv) { Stream.of("This", "is", "Java8", "Stream").forEach(System.out::println); String[] stringArray = new String[] { "Streams", "can", "be", "created", "from", "arrays" }; Arrays.stream(stringArray).forEach(System.out::println); }
From source file:Main.java
public static void main(String[] args) throws Exception { long uniqueWords = Files.lines(Paths.get("Main.java"), Charset.defaultCharset()) .flatMap(line -> Arrays.stream(line.split(" "))).distinct().count(); System.out.println("There are " + uniqueWords + " unique words in data.txt"); }
From source file:Main.java
public static void main(String[] args) throws Exception { List<Dish> menu = Arrays.asList(new Dish("pork", false, 800, Dish.Type.MEAT), new Dish("beef", false, 700, Dish.Type.MEAT), new Dish("chicken", false, 400, Dish.Type.MEAT), new Dish("rice", true, 350, Dish.Type.OTHER), new Dish("pizza", true, 550, Dish.Type.OTHER), new Dish("prawns", false, 400, Dish.Type.FISH), new Dish("salmon", false, 450, Dish.Type.FISH)); List<Integer> numbers = Arrays.asList(3, 4, 5, 1, 2); Arrays.stream(numbers.toArray()).forEach(System.out::println); int calories = menu.stream().mapToInt(Dish::getCalories).sum(); System.out.println("Number of calories:" + calories); }
From source file:Main.java
public static void main(String[] args) throws Exception { List<Dish> menu = Arrays.asList(new Dish("pork", false, 800, Dish.Type.MEAT), new Dish("beef", false, 700, Dish.Type.MEAT), new Dish("chicken", false, 400, Dish.Type.MEAT), new Dish("rice", true, 350, Dish.Type.OTHER), new Dish("pizza", true, 550, Dish.Type.OTHER), new Dish("prawns", false, 400, Dish.Type.FISH), new Dish("salmon", false, 450, Dish.Type.FISH)); List<Integer> numbers = Arrays.asList(3, 4, 5, 1, 2); Arrays.stream(numbers.toArray()).forEach(System.out::println); // max and OptionalInt OptionalInt maxCalories = menu.stream().mapToInt(Dish::getCalories).max(); System.out.println("Number of calories:" + maxCalories); }
From source file:Main.java
public static void main(String[] args) throws Exception { List<Dish> menu = Arrays.asList(new Dish("pork", false, 800, Dish.Type.MEAT), new Dish("beef", false, 700, Dish.Type.MEAT), new Dish("chicken", false, 400, Dish.Type.MEAT), new Dish("rice", true, 350, Dish.Type.OTHER), new Dish("pizza", true, 550, Dish.Type.OTHER), new Dish("prawns", false, 400, Dish.Type.FISH), new Dish("salmon", false, 450, Dish.Type.FISH)); List<Integer> numbers = Arrays.asList(3, 4, 5, 1, 2); Arrays.stream(numbers.toArray()).forEach(System.out::println); // max and OptionalInt OptionalInt maxCalories = menu.stream().mapToInt(Dish::getCalories).max(); System.out.println("Number of calories:" + maxCalories); int max;/*from www . j a v a 2 s . c om*/ if (maxCalories.isPresent()) { max = maxCalories.getAsInt(); } else { // we can choose a default value max = 1; } System.out.println(max); }