-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollexctionsEx.java
More file actions
40 lines (32 loc) · 1.08 KB
/
Copy pathCollexctionsEx.java
File metadata and controls
40 lines (32 loc) · 1.08 KB
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
package generics;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
public class CollexctionsEx {
static void printList(LinkedList<String> l) {
Iterator<String> iterator = l.iterator();
while(iterator.hasNext()){
String e = iterator.next();
String separator;
if (iterator.hasNext())
separator = "->";
else
separator = "\n";
System.out.print(e+separator);
}
}
public static void main(String[] args) {
LinkedList<String> myList = new LinkedList<String>();
myList.add("트랜스포머");
myList.add("스타워즈");
myList.add("매트릭스");
myList.add("터미네이터");
myList.add("아바타");
Collections.sort(myList);
printList(myList);
Collections.reverse(myList);
printList(myList);
int index = Collections.binarySearch(myList, "아바타") + 1;
System.out.println("아바타는 " + index + "번째 요소입니다.");
}
}