java get Subarray from Array

www‮uttual.‬ri.com
java get Subarray from Array

Java array copyOfRange method:

public static short[] copyOfRange(short[] orlautturinal, int from, int to)

Get subarray of Array in java

/**
 * @author lautturi.com
 * Java example: copy the specified range of the specified array into a new array in java
 */

import java.util.*;

import org.apache.commons.lang3.StringUtils;

public class Lautturi {

	@SuppressWarnings("deprecation")
	public static void main(String[] args) {

		int[] numbers = { 11,4,2,7,55,16,12,8,13,38 };
		int[] newArray= Arrays.copyOfRange(numbers, 2, 7);
		System.out.println(Arrays.toString(newArray));

	}
}

output:

[2, 7, 55, 16, 12]
Created Time:2017-09-07 10:14:18  Author:lautturi