Skip to Main Content

Java Programming

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!

Sort List<Object> values without using Collections(not using compare)

ss_itcNov 21 2018 — edited Nov 21 2018

Hi all,

I have a class type of Object and inserting these values into List.

Eg:  Employee class is having

int id, String name, String mail,

Employee e= new Employee(3,"Shankar","s@mail");

Employee e1= new Employee(2,"Sekahat","se@mail");

Employee e2= new Employee(37,"Sharat","sh@mail");

Employee e3= new Employee(1,"swaroop","s0@mail");

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

empList.add(e);

empList.add(e1);

empList.add(e2);

empList.add(e3);

Now I want to sort the list values based on id declared in the Employee class like below without using Collections.

1,"swaroop","s0@mail"

2,"Sekahat","se@mail"

3,"Shankar","s@mail"

37,"Sharat","sh@mail"

Can anyone please help on how to do this.

Thanks & Regards,

Suresh

Comments
Post Details
Added on Nov 21 2018
1 comment
170 views