Just decided to practice some code and i came across this problem. I made the ArrayList to take a list of ten numbers. If I input ten numbers like;
6
0
3
1
8
10
9
2
7
5 ,
It returns the ArrayList; [6, 0, 3, 1, 8, 10, 9, 2, 7, 5]
How do I return a sorted version of this array, like ascending or descending order? Thanks
package com.mypackage;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList al = new ArrayList();
System.out.println("Enter ten numbers");
for (int i = 1; i <= 10; i++) {
Object ob = sc.nextInt();
al.add(ob);
}
System.out.println(al);
}
}