Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int[] a = {2,5,4,6,9,7,4,5,8,7,4,5,6,3};
- int[] b = {6,9,8,7,4,2,3,6,5,2,1,4,7,8,5,6,3,6};
- //combine arrays
- IntStream combined = Stream.of(a,b).flatMapToInt(IntStream::of);
- //remove duplicates
- IntStream distinct = combined.distinct();
- //sort
- IntStream sorted = distinct.sorted();
- //filter some value
- IntStream lessThenFive = sorted.filter(n -> n<=5);
- //print array
- lessThenFive.forEach(System.out::println);
- //sum of all
- // int sum = sorted.sum();
- /*
- Note: sum and forEach are termianl methods so the stream will be close
- */
- //more to come
Add Comment
Please, Sign In to add comment