Skip to content

@MuhammadHewedy /LambdaExpr.java
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
java8 parallel sort
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.