Say I have an Object composed of a String and an Integer. How would I make an ArrayList<Object> with the objects with the highest integer value first and lowest last?
Asked
Active
Viewed 40 times
-3
Mureinik
- 297,002
- 52
- 306
- 350
Robert Colburn
- 29
- 7
-
5have you tried anything? – Reimeus Sep 30 '18 at 21:12
-
Search Stack Overflow thoroughly before posting. – Basil Bourque Sep 30 '18 at 21:26
1 Answers
1
You could sort them with a customer Comparator based on that property. With Java 8's enhancements, it should be pretty elegant:
myList.sort(Comparator.comparingInt(MyObject::getIntegerProperty).reversed());
Mureinik
- 297,002
- 52
- 306
- 350