LinkedList&Collections ํด๋์ค ํ์ฉ ์์
์ถ๊ฐ์ ์ผ๋ก Iterator ํ์ฉํด๋ณด๊ธฐ
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
public class LinkedListEx {
static void printList(LinkedList<String> list) {
Iterator<String> it = list.iterator();
while(it.hasNext()) {
System.out.print(it.next()+" ");
}
System.out.println("");
}
public static void main(String args[]) {
LinkedList<String> myList = new LinkedList<String>();
String[] names = {"Python", "Java", "Database", "Network"};
for(String s : names) {
myList.add(s);
}
printList(myList);
System.out.println(myList);
Collections.sort(myList); //๋ฌธ์์ ์ ๋ ฌ
System.out.println(myList);
Collections.reverse(myList); //์ญ์
System.out.println(myList);
}
}
์คํ ๊ฒฐ๊ณผ
728x90
๋ฐ์ํ
0