Java Arrays sort array using Arrays.sort()

Introduction

To sort Array using Arrays.sort() in Java

Arrays.sort(array);  

Full source

import java.util.Arrays;

public class Main {
  public static void main(String args[]) {
    // Allocate and initialize array. 
    int array[] = new int[10];  
    for(int i = 0; i < 10; i++)  
      array[i] = -3 * i;  //from  w  ww . jav a 2 s. c o m
  
    // Display, sort, and display the array. 
    System.out.println("Original contents: "+Arrays.toString(array));  

    Arrays.sort(array);  
    System.out.println("Original contents: "+Arrays.toString(array));  

  }
}



PreviousNext

Related