I would like to sort and binary search a static array of strings via the String.CompareTo comparator.
The problem is that both sorting, and binary searching requires that a Comparator object be passed in — So how do I pass in the built in string comparator?
The
Arraysclass has versions ofsort()andbinarySearch()which don’t require aComparator.For example, you can use the version ofArrays.sort()which just takes an array of objects. These methods call thecompareTo()method of the objects in the array.