Java tutorial
//package com.java2s; //License from project: BSD License import java.lang.reflect.*; public class Main { public static <T> T[] resize(T[] x, int size) { T[] out = null; try { out = (T[]) Array.newInstance(x.getClass().getComponentType(), size); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e.getMessage()); } int n = Math.min(x.length, size); System.arraycopy(x, 0, out, 0, n); return out; } public static int min(int[] x, int length) { int m = Integer.MAX_VALUE; for (int i = 0; i < length; i++) if (x[i] < m) m = x[i]; return m; } public static int min(int[] x) { return min(x, x.length); } public static double min(double[] x, int length) { double m = Double.POSITIVE_INFINITY; for (int i = 0; i < length; i++) if (x[i] < m) m = x[i]; return m; } }