Sort ArrayList using Collections.sort
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
public class SortArrayListTest {
public static void main(String[] args){
List list = new ArrayList();
list.add("banana");
list.add("apple");
list.add("orange");
Collections.sort(list);
Iterator it = list.listIterator();
while(it.hasNext()){
System.out.println(it.next());
}
}
}
OUTPUT
apple
banana
orange
No comments:
Post a Comment