Sort an Array Elements in Ascending Order in Java
Sort an Array Elements in Ascending Order in Java; is very simple here we use collection framework for sort array elements;
import java.util.Arrays;
import java.util.Collections;
class SortArrayDemo
{
public static void main(String[] args)
{
// int Array
Integer[] intArray = new Integer[] {
new Integer(25),
new Integer(10),
new Integer(18),
new Integer(12),
new Integer(40)
};
// Sorting int Array in descending order
Arrays.sort(intArray, Collections.reverseOrder());
// Displaying elements of int Array
System.out.println("Array Elements in Descending order:");
for (int i = 0; i < intArray.length; i++)
System.out.println(intArray[i]);
}
}
Output:
Array Elements in Descending order
25
10
18
12
40
Java Program to Sort an Array Elements in Ascending Order
No comments :
Post a Comment