Get Sub array

In this chapter you will learn:

  1. Subarray from array that starts at offset

Subarray from array that starts at offset

import java.util.Arrays;
//from  ja v  a2  s  .  c o  m
public class Main {
public static void main(String[] argv){
  int[] intArray = new int[]{1,2,3,4,5,6,7,8};
  int[] intSubArray = get(intArray,3,2);
  System.out.println(Arrays.toString(intSubArray));
}
  public static int[] get(int[] array, int offset, int length) {
    int[] result = new int[length];
    System.arraycopy(array, offset, result, 0, length);
    return result;
  }
}

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. Get array upperbound
  2. Get the number of dimensions
Home » Java Tutorial » Array
Java Array
Create an Array
Array Index and length
Multidimensional Arrays
Array examples
Array copy
Array compare
Array Binary search
Array Search
Array sort
Array to List
Convert array to Set
Array fill value
Array to String
Array element reverse
Array element delete
Array shuffle
Array element append
Array min / max value
Sub array search
Get Sub array
Array dimension reflection
Array clone