Given a partial API:
Final class Items implements no interfaces and has one constructor:
Items(String name, int value)
And given that you want to make collections of Items objects and sort them (using classes and interfaces in java.lang or java.util), sometimes by name, and sometimes by value, which are true? (Choose all that apply.).
compare()
method at least twice.compareTo()
method at least twice.B, D, and E are correct.
The most natural way to use the Java API in this case would be to create two classes, each of which implements Comparator.
Each class that implements Comparator will implement a compare()
method.
Once this is done, you'd use Collections.sort()
to sort the collections.