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.. ?
Asked
Active
Viewed 105 times
2
-
`sort()` could be a method of `List`. Ex: `mylist.sort()` is possible in Groovy. – jocki Mar 16 '15 at 16:49
-
1Do you understand the difference between `Collection` and `Collections`? – ControlAltDel Mar 16 '15 at 16:49
-
Collections contains utilities for the whole collections framework, including Lists. What's the issue with that? – Louis Wasserman Mar 16 '15 at 18:20
-
A StackedList wont sort() – Marcos Vasconcelos Mar 17 '15 at 11:46
1 Answers
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 Map
s, SortedMap
s, SortedSet
s, and, of course, Collection
s.
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