-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayList2.java
More file actions
33 lines (30 loc) · 934 Bytes
/
arrayList2.java
File metadata and controls
33 lines (30 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class arrayList2 {
public static void main(String[] args) {
List<Integer> numbers = new ArrayList<Integer>();
numbers.add(50);
numbers.add(40);
numbers.add(20);
numbers.add(30);
numbers.add(10);
numbers.size();
System.out.print("Unsorted: ");
for(int number : numbers){
System.out.print(number + " ");
}
System.out.println();
Collections.sort(numbers);
System.out.print("Sorted(Ascending): ");
for(int number : numbers){
System.out.print(number + " ");
}
System.out.println();
Collections.sort(numbers, Collections.reverseOrder());
System.out.print("Sorted(Descending): ");
for(int number : numbers){
System.out.print(number + " ");
}
}
}