SHARE
TWEET

Untitled

a guest Jun 25th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class People
  2. {
  3.  
  4.   private String name;
  5.   private String age;
  6.   private String address;
  7.  
  8.   public People(final String name, final String age, final String address)
  9.   {
  10.     this.name = name;
  11.     this.age = age;
  12.     this.address = address;
  13.   }
  14.  
  15.   public boolean isAttributeEqual(final People dupPeop)
  16.   {
  17.     return this.address.equals(dupPeop.address) && this.age.equals(dupPeop.age) && this.name.equals(dupPeop.name);
  18.   }
  19.  
  20.   public static void main(final String[] args)
  21.   {
  22.  
  23.     List<People> asList = Arrays.asList(new People("Sri", "28", "TN"), new People("Sri", "28", "TN"), new People("Sri", "28", "TN"),
  24.         new People("Pri", "28", "TN"));
  25.  
  26.     List<People> groupSimilar = groupSimilar(asList);
  27.  
  28.   }
  29.  
  30.   public static List<People> groupSimilar(final List<People> people)
  31.   {
  32.     List<People> duplicatePeople = new ArrayList<>(people);
  33.     for (Iterator<People> iterator = duplicatePeople.iterator(); iterator.hasNext();)
  34.     {
  35.       People people2 = iterator.next();
  36.       for (People orignalPeople : people)
  37.       {
  38.         if (!orignalPeople.equals(people2) && orignalPeople.isAttributeEqual(people2))
  39.         {
  40.           iterator.remove();
  41.           people2 = iterator.next();
  42.         }
  43.       }
  44.     }
  45.     return duplicatePeople;
  46.   }
  47. }
  48.      
  49. public class People
  50.      
  51. private String name;
  52. private String age;
  53. private String address;
  54.      
  55. public boolean isAttributeEqual(final People dupPeop)
  56.      
  57. List<People> asList = Arrays.asList(new People("Sri", "28", "TN"), new People("Sri", "28", "TN"), new People("Sri", "28", "TN"),
  58.     new People("Pri", "28", "TN"));
  59.  
  60. List<People> groupSimilar = groupSimilar(asList);
  61.      
  62. List<Person> persons
  63.      
  64. List<Person> people
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top