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








Syntax

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

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

Example

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

/*  w  w  w .  j  a  v a2  s .c o m*/

import java.util.Arrays;

public class Main {

   public static void main(String[] args) {

    long lArr[] = {131, 13, 2, 98, 11};

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

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

The code above generates the following result.