Example usage for java.util Collections reverseOrder

List of usage examples for java.util Collections reverseOrder

Introduction

In this page you can find the example usage for java.util Collections reverseOrder.

Prototype

@SuppressWarnings("unchecked")
public static <T> Comparator<T> reverseOrder() 

Source Link

Document

Returns a comparator that imposes the reverse of the natural ordering on a collection of objects that implement the Comparable interface.

Usage

From source file:Main.java

public static void main(String[] args) {
    ArrayList<String> arrayList = new ArrayList<String>();

    arrayList.add("A");
    arrayList.add("B");
    arrayList.add("C");
    arrayList.add("D");
    arrayList.add("E");

    Comparator comparator = Collections.reverseOrder();
    System.out.println(arrayList);

    Collections.sort(arrayList, comparator);
    System.out.println(arrayList);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String[] strArray = new String[] { "z", "a", "A" };
    List list = Arrays.asList(strArray);

    Collections.sort(list);/*from  w w w.  jav  a 2s .c om*/

    Collections.sort(list, String.CASE_INSENSITIVE_ORDER);

    Collections.sort(list, Collections.reverseOrder());

    Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
    Collections.reverse(list);
}

From source file:Main.java

public static void main(String[] args) {
    Integer[] points = new Integer[5];
    points[0] = 4;/*from   w  w w .  j a  v  a  2 s  .com*/
    points[1] = 3;
    points[2] = 0;
    points[3] = 4;
    points[4] = 4;

    Arrays.sort(points);
    System.out.println(Arrays.toString(points));

    Arrays.sort(points, Collections.reverseOrder());
    System.out.println(Arrays.toString(points));
}

From source file:Main.java

public static void main(String[] args) {
    ArrayList<String> arrayList = new ArrayList<String>();

    arrayList.add("A");
    arrayList.add("B");
    arrayList.add("C");
    arrayList.add("D");
    arrayList.add("java2s.com");

    Comparator comparator = Collections.reverseOrder();
    System.out.println(arrayList);

    Collections.sort(arrayList, comparator);
    System.out.println(arrayList);
}

From source file:Main.java

public static void main(String args[]) {
    // create arraylist       
    ArrayList<String> arlst = new ArrayList<String>();

    arlst.add("A");
    arlst.add("B");
    arlst.add("C");
    arlst.add("D");

    // search for key 
    int index = Collections.binarySearch(arlst, "D", Collections.reverseOrder());

    System.out.println(index);/*w  w  w  .  j a  v  a 2 s  .co m*/

    index = Collections.binarySearch(arlst, "D");

    System.out.println(index);
}

From source file:Main.java

public static void main(String args[]) {
    // create linked list object        
    LinkedList<Integer> list = new LinkedList<Integer>();

    // populate the list 
    list.add(-2);//from   www  .  j ava2  s .com
    list.add(2);
    list.add(-12);
    list.add(8);

    // sort the list
    Collections.sort(list, Collections.reverseOrder());

    System.out.println("List sorted in natural order: ");
    System.out.println(list);

}

From source file:MainClass.java

public static void main(String args[]) {
    LinkedList<Integer> ll = new LinkedList<Integer>();
    ll.add(-8);/* ww  w  . j  a va  2 s . c om*/
    ll.add(20);
    ll.add(-20);
    ll.add(8);

    Comparator<Integer> r = Collections.reverseOrder();

    Collections.sort(ll, r);

    System.out.print("List sorted in reverse: ");
    for (int i : ll) {
        System.out.print(i + " ");
    }

    System.out.println();

    Collections.shuffle(ll);

    System.out.print("List shuffled: ");
    for (int i : ll)
        System.out.print(i + " ");

    System.out.println();

    System.out.println("Minimum: " + Collections.min(ll));
    System.out.println("Maximum: " + Collections.max(ll));
}

From source file:Main.java

public static void main(String args[]) {
    // create linked list object        
    List<Integer> list = new LinkedList<Integer>();

    // populate the list 
    list.add(-8);//from   w w w.  j a va2s.  c  o  m
    list.add(2);
    list.add(-2);
    list.add(8);

    // create comparator for reverse order
    Comparator<Integer> cmp = Collections.reverseOrder();

    // sort the list
    Collections.sort(list, cmp);

    System.out.println("List sorted in ReverseOrder: ");
    System.out.println(list);

}

From source file:Main.java

public static void main(String args[]) {
    // create link list object 
    List<Integer> list = new LinkedList<Integer>();

    // populate the list  
    list.add(-8);// w  w  w. j ava 2s.c o  m
    list.add(4);
    list.add(-5);
    list.add(2);

    // comparing using natural ordering
    System.out.println("Min val: " + Collections.min(list));
    System.out.println("Min val: " + Collections.min(list, Collections.reverseOrder()));
}

From source file:Main.java

public static void main(String args[]) {
    // create link list object 
    List<Integer> list = new LinkedList<Integer>();

    // populate the list  
    list.add(-8);// w ww .j a  v a 2s . c  om
    list.add(4);
    list.add(-5);
    list.add(2);

    // comparing using natural ordering
    System.out.println("Max val: " + Collections.max(list));
    System.out.println("Max val: " + Collections.max(list, Collections.reverseOrder()));
}