Java List Sort isSorted(List list)

Here you can find the source of isSorted(List list)

Description

Check a given list of String if it's sorted or not

License

Open Source License

Parameter

Parameter Description
list - List of Strings to be checked if it's sorted

Return

- true if sorted; false otherwise

Declaration

public static boolean isSorted(List<String> list) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.List;

public class Main {
    /**/*from www.j  a va 2  s . c  om*/
     * Check a given list of String if it's sorted or not
     *
     * @param list - List of Strings to be checked if it's sorted
     * @return - true if sorted; false otherwise
     */
    public static boolean isSorted(List<String> list) {
        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;
    }
}

Related

  1. isSorted(Iterable list)
  2. isSorted(List list)
  3. isSorted(List list)
  4. isSorted(List> items, boolean asc)
  5. isSorted(List list, Comparator c)
  6. isSorted(List list)
  7. isSorted(List list)
  8. isSortedDescending(List list)
  9. isStringListSortedDesc(List list)