Program to sort Integer array using Arrays.sort (by default Arrays.sort will sort array in ascending order)

import java.util.Arrays;
/**
* @author AnkitMittal
* Copyright (c), AnkitMittal JavaMadeSoEasy.com
* Main class
*/
public class ArraysSort {
   public static void main(String...a){
       Integer intArray[]={2,3,1};
      
       System.out.print("Array before sorting : ");
       for(int i: intArray){
          System.out.print(i+" ");
       }
       Arrays.sort(intArray);
    
       System.out.print("\nArray after sorting : ");
       for(int i: intArray){
          System.out.print(i+" ");
       }
      
   }
}
/*OUTPUT
Array before sorting : 2 3 1
Array after sorting : 1 2 3
*/

No comments:

Post a Comment