Here is compatible with java 1.4 1.5-liner:
int[] array = { 1, 2, 3, 4, 5 }; int size = 3; int[] part = new int[size]; System.arraycopy(array, 0, part, 0, size);
You can do this in one line, but you will not have a link to the result.
To do a one-line, you can reorganize this into a method:
private static int[] partArray(int[] array, int size) { int[] part = new int[size]; System.arraycopy(array, 0, part, 0, size); return part; }
then call like this:
int[] part = partArray(array, 3);
Bohemian
source share