Java tutorial
//package com.java2s; import java.lang.reflect.*; public class Main { /** * Trims an array to a given size. * * @param f Array to be trimmed. * @return Trimmed array */ static public Object trimArray(Object[] list, int newSize) { Class type = list.getClass().getComponentType(); Object temp = Array.newInstance(type, newSize); System.arraycopy(list, 0, temp, 0, newSize); return temp; } static public Object trimArray(Object[] list, int start, int end) { int newSize = end - start; Class type = list.getClass().getComponentType(); Object temp = Array.newInstance(type, newSize); System.arraycopy(list, start, temp, 0, newSize); return temp; } }