Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

java8 parallel sort

View LambdaExpr.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
package helloJava8;
 
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
 
public class LambdaExpr {
 
public static void main(String[] args) throws IOException {
 
List<Employee> list = new ArrayList<>();
list.add(new Employee("Muhammad", "Abdullah"));
list.add(new Employee("Ahmad", "Yaser"));
list.add(new Employee("Ahmad", "Abdullah"));
 
list.stream().sorted((e1, e2) -> e1.getFirstName().compareTo(e2.getFirstName()))
.forEach(System.out::println);
 
System.out.println("--------------");
 
list.stream().parallel().sorted(Comparator.comparing(e -> e.getFirstName()))
.forEach(System.out::println);
}
 
static class Employee {
private String firstName;
private String lastName;
 
public Employee(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
 
public String getFirstName() {
return firstName;
}
 
public String getLastName() {
return lastName;
}
 
@Override
public String toString() {
return firstName + " " + lastName;
}
}
 
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.