-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise25.java
More file actions
30 lines (28 loc) · 832 Bytes
/
Copy pathExercise25.java
File metadata and controls
30 lines (28 loc) · 832 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
import java.util.*;
class MyList extends ArrayList<T> {
List myList = new ArrayList();
MyList(List l) { myList = l; }
@SuppressWarnings("unchecked")
MyList getReversed() {
ListIterator lit = myList.listIterator(myList.size());
List reverseMyList = new ArrayList();
while(lit.hasPrevious()) {
reverseMyList.add(lit.previous());
}
return new MyList(reverseMyList);
}
}
class Ex25 {
public static void main(String[] args) {
List<Integer> aList =
new ArrayList<Integer>(Arrays.asList(1,2,3,4,5));
System.out.println(aList);
System.out.println(aList.get(4));
aList.add(new Integer(6));
aList.addAll(new ArrayList<Integer>(Arrays.asList(7,8)));
System.out.println(aList);
System.out.println(aList.subList(2,4));
MyList ml = new MyList(aList);
System.out.println((ml.getReversed()).myList);
}
}