import java.util.*;
class ArrayListSorting {
public static void main(String args[]){
ArrayList<Integer> listofcountries = new ArrayList<Integer>();
listofcountries.add(89);
listofcountries.add(5);
listofcountries.add(3);
listofcountries.add(9);
/*Unsorted List*/
System.out.println("Before Sorting:");
for(int counter: listofcountries){
System.out.println(counter);
}
/* Sort statement*/
Collections.sort(listofcountries);
/* Sorted List*/
System.out.println("After Sorting:");
for(int counter: listofcountries){
System.out.println(counter);
}
}
}
OutPut : -
class ArrayListSorting {
public static void main(String args[]){
ArrayList<Integer> listofcountries = new ArrayList<Integer>();
listofcountries.add(89);
listofcountries.add(5);
listofcountries.add(3);
listofcountries.add(9);
/*Unsorted List*/
System.out.println("Before Sorting:");
for(int counter: listofcountries){
System.out.println(counter);
}
/* Sort statement*/
Collections.sort(listofcountries);
/* Sorted List*/
System.out.println("After Sorting:");
for(int counter: listofcountries){
System.out.println(counter);
}
}
}
OutPut : -
Add caption |
Comments
Post a Comment