Get Sub array
In this chapter you will learn:
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:
Home » Java Tutorial » Array