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

Java 8Object Oriented ProgrammingProgramming

The sort(Object[]) method of the java.util.Arrays class sorts the specified array of Objects into ascending order according to the natural ordering of its elements.

Example

import java.util.Arrays;

public class ArrayDemo {
   public static void main(String[] args) {
      Object ob[] = {27, 11, 44};
      for (Object number : ob) {
         System.out.println("Number = " + number);
      }
      Arrays.sort(ob);
      System.out.println("The sorted Object array is:");

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

Output

Number = 27
Number = 11
Number = 44
The sorted Object array is:
Number = 11
Number = 27
Number = 44
raja
Published on 08-Feb-2018 08:11:54
Advertisements