Java List Sort sort(List list)

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

Description

Sort ascending a list structure.

License

Open Source License

Declaration

public static final List sort(List list) 

Method Source Code

//package com.java2s;
/*//from   w  ww .j  a  va 2  s  .com
 * Copyright (c) 2007-2016 AREasy Runtime
 *
 * This library, AREasy Runtime and API for BMC Remedy AR System, is free software ("Licensed Software");
 * you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either version 2.1 of the License,
 * or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * including but not limited to, the implied warranty of MERCHANTABILITY, NONINFRINGEMENT,
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 */

import java.util.List;

public class Main {
    /**
     * Sort ascending a list structure.
     * The elements of list structure must be strings or other structure derivated by string
     */
    public static final List sort(List list) {
        for (int i = 0; list != null && i < list.size(); i++) {
            String actual = (String) list.get(i);
            for (int j = i; j < list.size(); j++) {
                String next = (String) list.get(j);
                if (actual.compareTo(next) > 0) {
                    list.set(i, next);
                    list.set(j, actual);

                    actual = next;
                }
            }
        }

        return list;
    }
}

Related

  1. sort( S list)
  2. sort(Collection list)
  3. Sort(Collection list)
  4. sort(Collection list)
  5. sort(final List list)
  6. sort(List list)
  7. sort(List list)
  8. sort(List list, Comparator comparator)
  9. sort(List list1, List list2)