+ 2

Java sorting of object field

I have made user defined objects and stored objects in arraylist, now i want to sort the arraylist on bases of one of the field of class One option is comparator and comparable but other than this is there any way?

21st Feb 2018, 3:50 PM
Manthan singh
Manthan singh - avatar
2 odpowiedzi
+ 11
you must override compareTo method...
21st Feb 2018, 3:54 PM
Vukan
Vukan - avatar
+ 1
I have tried to get each object from arraylist then compare it will other objects field and apply bubble sort but it won't work. I will try overloading tocompare
21st Feb 2018, 3:56 PM
Manthan singh
Manthan singh - avatar