Java Collection Tutorial - Java Arrays.sort(double[] a, int fromIndex, int toIndex)








Syntax

Arrays.sort(double[] a, int fromIndex, int toIndex) has the following syntax.

public static void sort(double[] a, int fromIndex, int toIndex)

Example

In the following code shows how to use Arrays.sort(double[] a, int fromIndex, int toIndex) method.

/*from  w  ww  . ja va  2 s .c  o  m*/


import java.util.Arrays;

public class Main {

   public static void main(String[] args) {

    // initializing unsorted double array
    double dArr[] = {13.1, 1.4, 0.7, 1.5, 0.7};

    System.out.println(Arrays.toString(dArr));
  
    // sorting array from index 0 to 3
    Arrays.sort(dArr, 0, 3);

    System.out.println(Arrays.toString(dArr));
  }
}

The code above generates the following result.