In java the sorting is done by using sort java arraylist. Sorting in java is simple to implement. Sort of object means to arrange the elements in well manner i.e. ascending order. In java sort arraylist only sorting of string is done. Strings can be sorting Arraylist in java depends on the on the type of the elements which are inserted. If the list having a set of randomly sorted String elements, sorting a string is done by comparing the alphabet.
The following code is used only for sorting a string in java arrarylist. ArrayList sort in java is easy way to sorting string in java. The String is sorted by the alphabetical order. The simple arraylist example java of sorting a string in java is given below.
Program of Java Sort arraylist with Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import java.util.*; // starts program of Sorting arraylist in java class Sort1 { public static void main(String args[]) { ArrayList<String> obj1=new ArrayList<String>(); // ArrayList sort method obj1.add("Tiger"); obj1.add("Monkey"); obj1.add("Dog"); obj1.add("Cat"); Collections.sort(obj1); // Method for java sort arraylist of objects Iterator it=obj1.iterator(); while(it.hasNext()) { System.out.println(it.next()); } } } //End of the arraylist example java |