Question: Define a Comparator for Strings such that a sort call on a List of strings sorts the strings by length, shortest to longest. Show the
Define a Comparator for Strings such that a sort call on a List of strings sorts the strings by length, shortest to longest. Show the entire class definition. For example, on input list ["ear", "za", "cabaret"], the list sorted according to this comparator will be ["za", "ear", "cabaret"] Hints: Start with the class declaration; it should implement Comparator with an appropriate type parameter. You only have to implement one method. Use a method of String to get its length. You can compare the lengths using <, >, and/or == correctly, or you can use Integer.compare (examples of each are shown in the notes). Write this in Eclipse, not MS Word or Google Docs, or youre gonna have a bad time.
Thanks!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
