Powered by Blogger.

Sort an Array Elements in Ascending Order in Java



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



facebook
google-plus
twitter
pinterest

No comments :

Post a Comment

HTML Tutorial

images

About Sitesbay

This blog is related to Java Tutorial, C++ Tutorial, C Tutorial, Online Earning tips and more in very simple and easy way. Here i will try to give complete idea related to all new technology.

Java Tutorial

Java is Object oriented programming language, It is more secure and high performance language.

C++ Tutorial

C++ is also Object oriented programming language, It is more simple and easy to learn.

 
https://sitesbay.blogspot.com/?utm_medium=d2898efa59afcc0bc411921036e22b767ca37b09