Advertisement
Guest User

Untitled

a guest
Jan 3rd, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. package com.cruncify.common;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashSet;
  5. import java.util.List;
  6. import java.util.Set;
  7.  
  8. import com.cruncify.admin.bean.Employee;
  9. import com.google.common.collect.Sets;
  10.  
  11. public class CollectionComparison {
  12.  
  13. public static void main (String args[])
  14. {
  15. List<Employee> list1 = new ArrayList<Employee>();
  16. Employee e = new Employee();
  17. Employee e1 = new Employee();
  18. e.setEmpId(1);
  19. e.setEmpEmail("ank2311@gmail.com");
  20. e.setEmpName("A");
  21. e.setEmpProgramName("Ci");
  22. e1.setEmpId(2);
  23. e1.setEmpEmail("a@gmail.com");
  24. e1.setEmpName("B");
  25. e1.setEmpProgramName("MS");
  26. list1.add(e1);
  27. list1.add(e);
  28.  
  29. List<Employee> list2 = new ArrayList<Employee>();
  30. Employee e2 = new Employee();
  31. e2.setEmpId(2);
  32. e2.setEmpEmail("b@gmail.com");
  33. e2.setEmpName("C");
  34. e2.setEmpProgramName("Ci");
  35. Employee e3 = new Employee();
  36. e3.setEmpEmail("c@gmail.com");
  37. e3.setEmpName("D");
  38. e3.setEmpProgramName("MS");
  39. e3.setEmpId(3);
  40. list2.add(e2);
  41. list2.add(e3);
  42. Set<Employee> set1 = new HashSet<Employee>(list1);
  43. Set<Employee> set2 = new HashSet<Employee>(list2);
  44.  
  45. Set<Employee> intersectionSet = Sets.intersection(set1, set2);
  46. List<Employee> intersection = new ArrayList<Employee>(intersectionSet);
  47. System.out.println(intersectionSet.size());
  48. System.out.println(intersection.get(0).getEmpId());
  49. System.out.println(intersection.get(0).getEmpEmail());
  50. System.out.println(intersection.get(0).getEmpName());
  51. System.out.println(intersection.get(0).getEmpProgramName());
  52. }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement