Java List Sort sortByLength(List list, final boolean ascending)

Here you can find the source of sortByLength(List list, final boolean ascending)

Description

sort By Length

License

Apache License

Declaration

public static void sortByLength(List<String> list,
            final boolean ascending) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Collections;
import java.util.Comparator;

import java.util.List;

public class Main {
    public static void sortByLength(List<String> list,
            final boolean ascending) {
        Comparator<String> c = new Comparator<String>() {
            public int compare(String e1, String e2) {
                int length1 = e1.length();
                int length2 = e2.length();
                if (ascending)
                    return Double.compare(length1, length2);
                else
                    return Double.compare(length2, length1);
            }//from  w w w.  j ava 2 s  . c  o  m
        };
        Collections.sort(list, c);
    }
}

Related

  1. sortAndReturn(final List list)
  2. sortBy(List> list, final Map orderBy)
  3. sortByByteDeux(List symbolAL, int delimiter)
  4. sortByClosestMatch(final List strings, final String toMatch)
  5. sortByLength(List li, String text)
  6. sortByOccurencies(List lsSame)
  7. sorted(List l, Comparator comparator)
  8. sorted(List l, Comparator comparator)
  9. sorted(List l)