Java Collection How to - Sort a subset of array elements








Question

We would like to know how to sort a subset of array elements.

Answer

       
import java.util.Arrays;
public class MainClass {
  public static void main(String[] a) {
    int array[] = { 2, 5, -2, 6, -3, 8, 0, -7, -9, 4 };
    Arrays.sort(array, 3, 7);/*from   w  w w .  j  a  v  a  2  s. c o  m*/
    for (int i : array) {
      System.out.println(i);
    }
  }
}

The code above generates the following result.