Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;

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

        // populate the list 
        list.add(-8);
        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);

    }
}