Roman Roman - 3 months ago 8
Java Question

How can I get a first element from a sorted list?

I used

Collections.sort(playersList);
to sort a
List
. So, I think
playersList
is sorted now. But how can I get the first element of the list?
playersList[0]
does not work.

Answer
playersList.get(0)

Java has limited operator polymorphism. So you use the get() method on List objects, not the array index operator ([])

Comments