Java Utililty Methods List Sort

List of utility methods to do List Sort

Description

The list of methods to do List Sort are organized into topic(s).

Method

booleanisSorted(List list)
is Sorted
return isSorted(list, true);
booleanisSorted(List list)
Determine if the given list is sorted
Comparable prevItem = null;
for (Comparable currItem : list) {
    if (prevItem != null && currItem.compareTo(prevItem) < 0) {
        return false;
    prevItem = currItem;
return true;
...
booleanisSorted(List> items, boolean asc)
is Sorted
for (int n = 0; n < items.size() - 1; n++) {
    Comparable<T> current = items.get(n);
    Comparable<T> next = items.get(n + 1);
    int cmp = current.compareTo((T) next);
    if (asc && cmp > 0) {
        return false;
    } else if (!asc && cmp < 0) {
        return false;
...
booleanisSorted(List list, Comparator c)
Checks that the list is sorted
if (list.isEmpty())
    return true;
Iterator<E> i = list.iterator();
E lastR = i.next();
while (i.hasNext()) {
    E r = i.next();
    if (c.compare(lastR, r) > 0)
        return false;
...
booleanisSorted(List list)
Check a given list of String if it's sorted or not
boolean sorted = true;
for (int i = 1; i < list.size(); i++) {
    if (list.get(i - 1).compareTo(list.get(i)) > 0) {
        sorted = false;
return sorted;
booleanisSorted(List list)
checks wether or not the list given is sorted
for (int i = 1; i < list.size(); ++i) {
    if (list.get(i - 1).compareTo(list.get(i)) > 0) {
        return false;
return true;
booleanisSorted(List list)
Returns whether a list is strictly sorted.
T prev = null;
for (T t : list) {
    if (prev != null && ((Comparable<T>) prev).compareTo(t) >= 0) {
        return false;
    prev = t;
return true;
...
booleanisSortedDescending(List list)
is Sorted Descending
if (list.size() < 2)
    return true;
for (int i = 1; i < list.size(); i++) {
    if (list.get(i - 1) < list.get(i)) {
        return false;
return true;
...
booleanisStringListSortedDesc(List list)
Determines of the data in a list is sorted in descending order
boolean sorted = true;
Iterator<String> iList = list.iterator();
String curr = iList.next();
while (iList.hasNext()) {
    String next = iList.next();
    if (curr.compareTo(next) < 0) {
        sorted = false;
        break;
...
booleanisUnsortedEventsMatch(List actual, List expected)
is Unsorted Events Match
if (actual.size() != expected.size()) {
    return false;
} else {
    for (int i = 0; i < actual.size(); i++) {
        boolean isThere = false;
        for (int j = 0; j < expected.size(); j++) {
            if (Arrays.equals(actual.get(i), expected.get(j))) {
                isThere = true;
...