import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Checklist;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Java Program to type Checklist of object in
reverse order. We are going to see examples of
* sorting Array Checklist in reverse order of each
default ordering in addition to any
* customized ordering imposed by Compartor.
*
* @creator Javin Paul
*/
public class CollectionSorting
{
personal static last
Logger logger = LoggerFactory.getLogger(CollectionSorting.class);
public static void
foremost(String args[]) {
// Creating
and initializing Assortment to type in reverse order
// Integer
will likely be sorted in reverse numeric order
Checklist<Integer> assortment = new ArrayList<Integer>();
assortment.add(101);
assortment.add(201);
assortment.add(105);
assortment.add(302);
logger.debug(“Present order in Assortment :
“ + assortment);
// Sorting
Assortment in reverse order
Collections.type(assortment,
Collections.reverseOrder());
logger.debug(“Sorted on Reverse order in
Assortment : {}”, assortment);
// Sorting
Checklist of String in reverse Order
Checklist<String> alphabets = Arrays.asList(“A”,
“B”, “C”, “D”);
logger.debug(“Present order in Checklist of String
: {}”, alphabets);
// Sorting
Checklist in reverse Order
Collections.type(alphabets,
Collections.reverseOrder());
logger.debug(“Checklist of String sorted in reverse
order {}”, alphabets);
}
}
Output
[main] DEBUG CollectionSorting – Present order in Assortment : [101, 201,
105, 302]
[main] DEBUG CollectionSorting – Sorted on Reverse order in Assortment : [302, 201,
105, 101]
[main] DEBUG CollectionSorting – Present order in Checklist of String : [A, B, C,
D]
[main] DEBUG CollectionSorting – Checklist of String sorted in reverse order [D,
C, B, A]