tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Tools and Libs > Google Guava > Collections > Reverse Ordering

Reverse Ordering 

Google Guava is a java library with lot of utilities and reusable components. This requires the library guava-10.0.jar to be in classpath. The following example shows using Ordering.reverse() API. It returns the reverse of the current Ordering.

File Name  :  
com/bethecoder/tutorials/guava/collection_tests/OrderingReverseTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.guava.collection_tests;

import java.util.List;

import com.google.common.collect.Lists;
import com.google.common.collect.Ordering;

public class OrderingReverseTest {

  /**
   @param args
   */
  public static void main(String[] args) {

    List<Integer> intList = Lists.newArrayList(576129843);
    List<Integer> sortedCopy = Ordering.natural().reverse().sortedCopy(intList);
    
    System.out.println("Original List : " + intList);
    System.out.println("Sorted copy : " + sortedCopy);
    
    List<String> strList = Lists.newArrayList("DD""BB""CC""AA");
    List<String> strSortedCopy = Ordering.natural().reverse().sortedCopy(strList);
    
    System.out.println("Original List : " + strList);
    System.out.println("Sorted copy : " + strSortedCopy);
  }
}
   

It gives the following output,
Original List : [5, 7, 6, 1, 2, 9, 8, 4, 3]
Sorted copy : [9, 8, 7, 6, 5, 4, 3, 2, 1]

Original List : [DD, BB, CC, AA]
Sorted copy : [DD, CC, BB, AA]


                    Print

   



Books Recommendation

 
 
bl  br