How to determine if a List is sorted in Java?
Posted
by FarmBoy
on Stack Overflow
See other posts from Stack Overflow
or by FarmBoy
Published on 2010-06-15T16:23:28Z
Indexed on
2010/06/15
16:32 UTC
Read the original article
Hit count: 410
I would like a method that takes a List<T>
where T
implements Comparable
and returns true
or false
depending on whether the list is sorted or not.
What is the best way to implement this in Java? It's obvious that generics and wildcards are meant to be able to handle such things easily, but I'm getting all tangled up.
It would also be nice to have an analogous method to check if the list is in reverse order.
© Stack Overflow or respective owner