2

When sort method works upon only Lists, I feel keeping it in Collections class is somewhat buggy. Shouldn't there be a separate class dedicated to Lists? Maybe AbstractList or something like ListUtil.. ?

Mohit Kanwar
  • 2,962
  • 7
  • 39
  • 59

1 Answers1

4

Collections is a helper class for all collections regardless of their type. In addition to method for the List there are methods specific to Maps, SortedMaps, SortedSets, and, of course, Collections.

Although making a separate helper for lists alone would be a justifiable choice, using a single helper class as a single place for all collection helpers makes perfect sense as well: it makes it easier for developers to remember where the methods are, because only one class is there.

Note that starting with Java-8 you can call sort as a default method implementation on List<T>, making the implementation even easier to locate.

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523