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

Listsort(String prefix, int[] a, List list)
sort
if (a.length == 1) {
    list.add(prefix + a[0]);
for (int i = 0; i < a.length; i++) {
    sort(prefix + a[i], copy(a, i), list);
return list;
StringsortAndFormat(List stringList)
sort And Format
if (stringList == null) {
    return "";
String[] stringArray = stringList.toArray(new String[0]);
Arrays.sort(stringArray);
StringBuilder buffer = new StringBuilder();
for (int i = 0; i < stringArray.length; i++) {
    if (i > 0) {
...
ListsortAndReturn(final List list)
sort And Return
Collections.sort(list);
return list;
voidsortBy(List> list, final Map orderBy)
The purpose of this method is to sort the rows in the delta when 'summary' is turned off.
if (orderBy == null)
    return;
Collections.sort(list, new Comparator<Map<String, ? extends Comparable>>() {
    @Override
    public int compare(Map<String, ? extends Comparable> m1, Map<String, ? extends Comparable> m2) {
        for (Map.Entry<String, String> obe : orderBy.entrySet()) {
            String sortOrder = obe.getValue();
            if (sortOrder == null)
...
ArrayList>sortByByteDeux(List symbolAL, int delimiter)
sort By Byte Deux
ArrayList<Character> bucketOneAL = new ArrayList<Character>();
ArrayList<Character> bucketTwoAL = new ArrayList<Character>();
for (int i = 0; i < symbolAL.size(); i += 2) {
    String byteS = symbolAL.get(i).toString() + symbolAL.get(i + 1).toString();
    int tempI = Integer.parseInt(byteS, 16);
    if (tempI > delimiter) {
        bucketTwoAL.add(symbolAL.get(i));
        bucketTwoAL.add(symbolAL.get(i + 1));
...
voidsortByClosestMatch(final List strings, final String toMatch)
sort By Closest Match
subStrings.clear();
String toFind = toMatch.replaceAll("[_\\s]", "").toLowerCase();
Map<String, Double> scores = new HashMap<>();
strings.sort((string1, string2) -> {
    if (!scores.containsKey(string1)) {
        scores.put(string1, getScore(string1, toFind));
    if (!scores.containsKey(string2)) {
...
voidsortByLength(List li, String text)
Sorts the supplied list ordering the items closest to the length of the supplied text first, followed by all larger, and then all shorter.
List<String> tmpStr = new ArrayList<>(li);
List<String> equalList = new ArrayList<>();
List<String> largerList = new ArrayList<>();
List<String> smallerList = new ArrayList<>();
li.clear();
int l = text.length();
for (String s : tmpStr) {
    if (s.length() == l) {
...
voidsortByLength(List list, final boolean ascending)
sort By Length
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);
...
ArrayListsortByOccurencies(List lsSame)
sort By Occurencies
HashMap<String, Integer> hsOccs = new HashMap<String, Integer>();
for (String each : lsSame) {
    if (!hsOccs.containsKey(each)) {
        hsOccs.put(each, 1);
    } else {
        hsOccs.put(each, hsOccs.get(each) + 1);
Iterator it = hsOccs.entrySet().iterator();
while (it.hasNext()) {
    Map.Entry mp = (Map.Entry) it.next();
    Integer val = (Integer) mp.getValue();
    if (val < 4) {
        it.remove();
if (hsOccs.isEmpty()) {
    return null;
ArrayList<Map.Entry<String, Integer>> lsRes = new ArrayList<Map.Entry<String, Integer>>(hsOccs.entrySet());
Collections.sort(lsRes, new Comparator<Map.Entry<String, Integer>>() {
    @Override
    public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
        return o2.getValue().compareTo(o1.getValue());
});
ArrayList<String> lsRet = new ArrayList<String>();
for (Map.Entry mp : lsRes) {
    lsRet.add((String) mp.getKey() + "=" + (String) Integer.toString((Integer) mp.getValue()));
return lsRet;
Listsorted(List l, Comparator comparator)
sorted
List<T> copy = new ArrayList<T>(l);
Collections.sort(copy, comparator);
return copy;