Java List Sort sort(List list, Comparator comparator)

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

Description

Creates a copy of and sorts the given list.

License

Open Source License

Parameter

Parameter Description
T type.
list the list to sort.
comparator the comparator to use when sorting.

Return

a sorted list.

Declaration

public static <T> List<T> sort(List<T> list,
        Comparator<? super T> comparator) 

Method Source Code

//package com.java2s;
import java.util.ArrayList;

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

import java.util.List;

public class Main {
    /**/*  ww w. ja  v  a  2s.c o m*/
     * Creates a copy of and sorts the given list.
     * 
     * @param <T> type.
     * @param list the list to sort.
     * @param comparator the comparator to use when sorting.
     * @return a sorted list.
     */
    public static <T> List<T> sort(List<T> list,
            Comparator<? super T> comparator) {
        List<T> copy = new ArrayList<>(list);
        Collections.sort(copy, comparator);
        return copy;
    }
}

Related

  1. sort(List list)
  2. sort(List list)
  3. sort(List list)
  4. sort(List list)
  5. sort(List list, Comparator c)
  6. sort(List list, Comparator comparator)
  7. sort(List list, Comparator comparator, String sort, boolean sortOrder)
  8. sort(List objs, Comparator cp)
  9. sort(Set list, Comparator comparator)