import java.util.*;
class StreamApiExample {
public static void main(String[] args) {
List<Integer> nums = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5));
System.out.println(nums);
List<Integer> arr_nums = nums.stream().map(x -> x * x).toList();
System.out.println(arr_nums);
//With Multithreading - this will split and run in parallel cores
List<Integer> cube_nums = nums.parallelStream().map(x -> x * x * x).toList();
System.out.println(cube_nums);
List<Integer> even_nums = nums.stream().filter(x -> x % 2 == 0).toList();
System.out.println(even_nums);
int sum_of_nums = nums.stream().reduce((t, x) -> t + x).orElse(0);
System.out.println(sum_of_nums);
}
}
I like it when people get together and share thoughts. Great blog, stick with it!
Hi there to every one, since I am actually keen of reading this website’s post to be updated on a regular basis. It includes nice material.
Ahaa, its pleasant dialogue about this article here at this web site, I have read all that, so at this time me also commenting here.