Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.util.stream.*;
- public class Main
- {
- public static void main(String[] args)
- {
- double[] sample = {20, 12, 34, 45, 11, 23, 45};
- DoubleStream ds = Arrays.stream(sample);
- System.out.println(ds.count());
- // Another example
- ds = Arrays.stream(sample);
- ds.forEach(System.out::println);
- System.out.println("In one statement ...");
- Arrays.stream(sample).forEach(System.out::println);
- // Selection
- long count =
- Arrays.stream(sample).filter(value -> value >= 30).count();
- System.out.println(count);
- Arrays.stream(sample)
- .filter(value -> value >= 30)
- .forEach(System.out::println);
- Arrays.stream(sample)
- .filter(value -> value >= 30)
- .forEach(Main::printOneLine);
- // Saving to array
- double[] above30 =
- Arrays.stream(sample)
- .filter(v -> v > 30)
- .toArray();
- System.out.println(above30.length);
- for (int i = 0; i < above30.length; i++)
- System.out.println(above30[i]);
- }
- public static void printOneLine(double value)
- {
- System.out.print(value + " ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement