Java Utililty Methods Collection Sort

List of utility methods to do Collection Sort

  1. HOME
  2. Java
  3. C
  4. Collection Sort

Description

The list of methods to do Collection Sort are organized into topic(s).

Method

List getSorted(Collection collection)
Return a sorted list with the collection's elements.
List<T> ret = new ArrayList<T>(collection.size());
ret.addAll(collection);
Collections.sort(ret);
return ret;
boolean isSort(Collection c)
is Sort
E pointer = null, next;
Iterator<E> it = c.iterator();
if (it.hasNext())
 pointer = it.next();
while (it.hasNext()) {
 next = it.next();
 if (pointer.compareTo(next) > 0)
 return false;
...
void sort(Collection collection)
sort
if (isNotEmpty(collection)) {
 Object[] objs = collectionToArray(collection);
 Arrays.sort(objs);
 collection.clear();
 collection.addAll(arrayToCollection(objs));
List sort(Collection collection, Comparator comparator)
sort
List<T> list = new ArrayList<T>(collection);
Collections.sort(list, comparator);
return list;
List sort(Collection items)
Sort the collection and return as list.
List<T> list = toList(items);
Collections.sort(list);
return list;
List
    > sortByDescendingOrder(Map collection)
    sort By Descending Order
    List<Map.Entry<T, Double>> list = new ArrayList<Map.Entry<T, Double>>(collection.entrySet());
    Collections.sort(list, new Comparator<Map.Entry<T, Double>>() {
     public int compare(Map.Entry<T, Double> o1, Map.Entry<T, Double> o2) {
     if (o1.getValue() > o2.getValue()) {
     return -1;
     } else if (o1.getValue() < o2.getValue()) {
     return 1;
     } else {
    ...
    
List> sortClassesByLevelOfInheritance(Collection> classes)
sort Classes By Level Of Inheritance
List<Class<?>> result = new ArrayList<Class<?>>(classes);
Collections.sort(result, new Comparator<Class<?>>() {
 public int compare(Class<?> c1, Class<?> c2) {
 int l1 = getLevelOfInheritance(c1);
 int l2 = getLevelOfInheritance(c2);
 if (l1 < l2) {
 return -1;
 } else if (l1 > l2) {
...
List sorted(Collection coll)
sorted
if (coll == null || coll.isEmpty()) {
 return Collections.emptyList();
List<T> list = new ArrayList<>(coll);
Collections.sort(list);
return list;
List sorted(Collection input)
sorted
List<T> sortable = new ArrayList<>(input);
Collections.sort(sortable);
return sortable;
ArrayList sorted(Collection coll)
sorted
final ArrayList<E> result = new ArrayList<E>(coll);
Collections.sort(result);
assert result != null;
assert result != coll;
return result;


AltStyle によって変換されたページ (->オリジナル) /