Created
April 21, 2014 11:11
-
-
Save mhewedy/11139654 to your computer and use it in GitHub Desktop.
java8 parallel sort
This file contains 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
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