Java Arrays sort sub array

Description

Java Arrays sort sub array

import java.util.Arrays;
public class Main {
  public static void main(String[] a) {
    int array[] = { 1232, 3215, -1232, 6123, -3312, 8123, 3210, -1237, -3219, 4123 };
    //from  w  w  w  . j a  v a  2s .  co  m
    System.out.println(Arrays.toString(array));
    
    int startIndex = 3;
    int endIndex = 7;
    Arrays.sort(array, startIndex, endIndex);
    System.out.println(Arrays.toString(array));

  }
}
import java.util.Arrays;

public class Main {

  public static void main(String[] args) throws Exception {
    int[] myArray = { 15, 2, 17, 3, 19, 11, 4, 111 };
    System.out.println(Arrays.toString(myArray));
    Arrays.sort(myArray, 2, 6);// w  w w. j  a  v  a  2 s  . c  o  m
    System.out.println(Arrays.toString(myArray));
  }
}



PreviousNext

Related