How to sort elements in Ascending and Descending Order?

SOLUTION :-

package mv;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class AscendingAndDescendingIntegers {

public static void main(String[] args) {

    List<Integer> list=new ArrayList<>();
    list.add(4);
    list.add(1);
    list.add(2);
    list.add(5);
    list.add(3);

    Collections.sort(list);
    System.out.println("List in Ascending order:"+list);
    Collections.reverse(list);
    System.out.println("List in Descending order:"+list);

}

}

Leave a Reply

Your email address will not be published. Required fields are marked *

*