Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Question on removing duplicate data in a collection

816802Sep 12 2018 — edited Oct 21 2018

Hi All,

I have the below employee class defined.

public class Employee implements Comparable<Employee> {

private int id;

private String name;

private String salary;

private String recordStatus;

private int key;

public Employee(int id, String name, String salary, int key) {

super();

this.id = id;

this.name = name;

this.salary = salary;

this.key = key;

}}

Now I have a list of type Employee.

List<Employee> list = new ArrayList<Employee>();

list.add(new Employee(123, "zMadhu", "1000$",1));

list.add(new Employee(332, "bSudhan", "2000$",2));

list.add(new Employee(54, "cKongarass", "3000$",3));

list.add(new Employee(54, "xKongarass", "3000$",4));

list.add(new Employee(54, "aKongarass", "3000$",5));

Now I want to remove data from this list and have only unique IDS. I.E. I am expecting 54,123,332.

Want to see how I can do it. Much appreciate your help here.

Comments
Post Details
Added on Sep 12 2018
2 comments
229 views