Guest User

Untitled

a guest
Apr 27th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. public class Diggu {
  2.  
  3. class Employee{
  4. private int id;
  5. private String name;
  6. public Employee(int id, String name){
  7. this.id = id;
  8. this.name = name;
  9. }
  10.  
  11. public int getId() {
  12. return id;
  13. }
  14.  
  15. public void setId(int id) {
  16. this.id = id;
  17. }
  18.  
  19. public String getName() {
  20. return name;
  21. }
  22.  
  23. public void setName(String name) {
  24. this.name = name;
  25. }
  26.  
  27.  
  28.  
  29. }
  30.  
  31. public void ra(){
  32. List<Employee> employee = Arrays.asList(new Employee(1, "John"), new Employee(3, "JOHN"), new Employee(2, "BOB"));
  33. System.out.println(""+ employee.size());
  34. List<Employee> unique = employee.stream()
  35. .collect(collectingAndThen(toCollection(() -> new TreeSet<>(comparing(Employee::getName))),
  36. ArrayList::new));
  37. System.out.println(""+ unique.size());
  38. }
  39. public static void main(String[] args) {
  40. new Diggu().ra();
  41. }
  42. }
Add Comment
Please, Sign In to add comment