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








Syntax

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

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

Example

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

/*w  w  w. ja  v a  2  s. c o m*/

import java.util.Arrays;

public class Main {

   public static void main(String[] args) {

    // initializing unsorted short array
    short[] sArr = {13, 13, 11, 9, 21};

    System.out.println(Arrays.toString(sArr));
  
    // sorting array from index 1 to 4
    Arrays.sort(sArr, 1, 4);

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

The code above generates the following result.