What does the method sort(int[] a) do in java?

Java 8Object Oriented ProgrammingProgramming

The sort(int[]) method of the java.util.Arrays class sorts the specified array of integer values into ascending numerical order.

Example

import java.util.Arrays;

public class ArrayDemo {
   public static void main(String[] args) {
      int iArr[] = {2, 1, 9, 6, 4};

      for (int number : iArr) {
         System.out.println("Number = " + number);
      }
      Arrays.sort(iArr);
      System.out.println("The sorted int array is:");

      for (int number : iArr) {
         System.out.println("Number = " + number);
      }
   }
}

Output 

Number = 2
Number = 1
Number = 9
Number = 6
Number = 4
The sorted int array is:
Number = 1
Number = 2
Number = 4
Number = 6
Number = 9
raja
Published on 16-Jan-2018 10:38:54
Advertisements