Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.cruncify.common;
- import java.util.ArrayList;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Set;
- import com.cruncify.admin.bean.Employee;
- import com.google.common.collect.Sets;
- public class CollectionComparison {
- public static void main (String args[])
- {
- List<Employee> list1 = new ArrayList<Employee>();
- Employee e = new Employee();
- Employee e1 = new Employee();
- e.setEmpId(1);
- e.setEmpEmail("ank2311@gmail.com");
- e.setEmpName("A");
- e.setEmpProgramName("Ci");
- e1.setEmpId(2);
- e1.setEmpEmail("a@gmail.com");
- e1.setEmpName("B");
- e1.setEmpProgramName("MS");
- list1.add(e1);
- list1.add(e);
- List<Employee> list2 = new ArrayList<Employee>();
- Employee e2 = new Employee();
- e2.setEmpId(2);
- e2.setEmpEmail("b@gmail.com");
- e2.setEmpName("C");
- e2.setEmpProgramName("Ci");
- Employee e3 = new Employee();
- e3.setEmpEmail("c@gmail.com");
- e3.setEmpName("D");
- e3.setEmpProgramName("MS");
- e3.setEmpId(3);
- list2.add(e2);
- list2.add(e3);
- Set<Employee> set1 = new HashSet<Employee>(list1);
- Set<Employee> set2 = new HashSet<Employee>(list2);
- Set<Employee> intersectionSet = Sets.intersection(set1, set2);
- List<Employee> intersection = new ArrayList<Employee>(intersectionSet);
- System.out.println(intersectionSet.size());
- System.out.println(intersection.get(0).getEmpId());
- System.out.println(intersection.get(0).getEmpEmail());
- System.out.println(intersection.get(0).getEmpName());
- System.out.println(intersection.get(0).getEmpProgramName());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement