-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path07_sorting.java
49 lines (39 loc) · 1.26 KB
/
07_sorting.java
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.*;
class MyCollections {
public static void main(String args[]) {
example_arrayList_string();
}
public static void example_arrayList_string() {
// Create using
// ArrayList <Data Type> variable = new ArrayList <Data Type>();
ArrayList<String> workingDays = new ArrayList<String>();
workingDays.add("Monday");
workingDays.add("Tuesday");
workingDays.add("Wednesday");
workingDays.add("Friday");
// Add to a specific index
workingDays.add(3, "Thursday");
// Iterate over the array list
Iterator itor = workingDays.iterator();
System.out.println("\nUnorted Workdays");
while( itor.hasNext() ) {
System.out.println(" - " + itor.next() );
}
// SORTING
Collections.sort(workingDays);
// Iterate over the array list
itor = workingDays.iterator();
System.out.println("\nSorted Workdays");
while( itor.hasNext() ) {
System.out.println(" - " + itor.next() );
}
// SORTING in Reverse Order
Collections.sort(workingDays, Collections.reverseOrder());
// Iterate over the array list
itor = workingDays.iterator();
System.out.println("\nSorted (Reverse) Workdays");
while( itor.hasNext() ) {
System.out.println(" - " + itor.next() );
}
}
}