-3

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?

Mureinik
  • 297,002
  • 52
  • 306
  • 350

1 Answers1

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