Quantcast
Channel: Sorting an array based on different properties of objects by overriding compareTo() method - Stack Overflow
Browsing all 4 articles
Browse latest View live

Answer by Basil Bourque for Sorting an array based on different properties of...

The Comparator interface now offers methods to more conveniently solve your problem.Add a static variable to your class.static Comparator < Student > comparator = Comparator .comparing( Student...

View Article



Answer by Ujwal Kumar for Sorting an array based on different properties of...

I am assuming that you want to sort the data based on ascending order of color, if color is equal then you want to sort in descending order of size, if size is also equal, then sort on ascending order...

View Article

Answer by Vladimir Stanciu for Sorting an array based on different properties...

You should go on with comparing the other fields only if the preceding ones are equal, meaning your compareTo result is 0, not greater than 0.You can take a look here.

View Article

Sorting an array based on different properties of objects by overriding...

I have a list of Student objects, each of them has 3 properties. Color, Size and their names. I want to sort them in ascending order based on their color first, followed by descending order of size and...

View Article
Browsing all 4 articles
Browse latest View live




Latest Images