Answer by SMA for Sort ArrayList of custom object and reorder in Java
To remove duplicates and keep the sorted order, i would suggest the following:You store the Objects of type MyObject in a ListSort them as you are doing with x field iterate over the list and check for...
View ArticleAnswer by Tkachuk_Evgen for Sort ArrayList of custom object and reorder in Java
You can implement Comparable<MyObject> in MyObject class and then use TreeSet<MyObject>, as result you have sorted unique values.
View ArticleAnswer by nitishagar for Sort ArrayList of custom object and reorder in Java
For getting unique elements for your custom class you can just add all elements to something like HashSet. For using this you need to override the Object#hashCode() method to let it return the same...
View ArticleAnswer by yole for Sort ArrayList of custom object and reorder in Java
Sorting a list twice with different comparators will not work. You need to compare both x and y in the same comparator.public int compare(MyObject lhs, MyObject rhs) { int result =...
View ArticleSort ArrayList of custom object and reorder in Java
I have a ArrayList of CustomObject, my object is simply made of two values x and y MyObject = (double)x && (double)y What I want to do is: remove duplicate from array : simply remove duplicate...
View Article