Question: Declare and instantiate a custom comparator called myComparator (anonymous class instance) that overrides the method compare() . This method should accept two String objects as
Declare and instantiate a custom comparator called myComparator (anonymous class instance) that overrides the method compare(). This method should accept two String objects as input parameters. This comparator should return the higher value if the length of the second String argument is bigger. In other words, this custom comparator can be used to sort String objects based on the length of the strings, with the longer strings being considered "bigger" than the shorter strings. Such comparator can be used, for example, to sort a collection of names represented as String objects. You do not need to implement the tester program or anything else outside of the declaration, instantiation, and implementation of this custom comparator.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
