Java tutorial
//package com.java2s; //License from project: BSD License import java.lang.reflect.*; public class Main { public static <T> T[] subArray(T[] x, int start, int len) { if (start + len > x.length) throw new IllegalArgumentException("length + start > x.length"); T[] out = null; try { out = (T[]) Array.newInstance(x.getClass().getComponentType(), len); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e.getMessage()); } System.arraycopy(x, start, out, 0, len); return out; } }