Created
May 2, 2019 17:55
-
-
Save lrlucena/fb8fe0d08f2614b12f94d203d797781c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
public class ParallelStreamDemo { | |
public static void main(String[] args) { | |
long t1, t2; | |
List<Employee> eList = new ArrayList<Employee>(); | |
for(int i=0; i<100; i++) { | |
eList.add(new Employee("A", 20000)); | |
eList.add(new Employee("B", 3000)); | |
eList.add(new Employee("C", 15002)); | |
eList.add(new Employee("D", 7856)); | |
eList.add(new Employee("E", 200)); | |
eList.add(new Employee("F", 50000)); | |
} | |
/***** Here We Are Creating A 'Sequential Stream' & Displaying The Result *****/ | |
t1 = System.currentTimeMillis(); | |
System.out.println("Sequential Stream Count?= " + eList.stream().filter(e -> e.getSalary() > 15000).count()); | |
t2 = System.currentTimeMillis(); | |
System.out.println("Sequential Stream Time Taken?= " + (t2-t1) + "\n"); | |
/***** Here We Are Creating A 'Parallel Stream' & Displaying The Result *****/ | |
t1 = System.currentTimeMillis(); | |
System.out.println("Parallel Stream Count?= " + eList.parallelStream().filter(e -> e.getSalary() > 15000).count()); | |
t2 = System.currentTimeMillis(); | |
System.out.println("Parallel Stream Time Taken?= " + (t2-t1)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment