Java array copy to double its size
import java.util.Arrays; public class Main { public static void main (String args[]) { int array1[] = {1, 2, 3, 4, 5}; System.out.println("Original size: " + array1.length); System.out.println(Arrays.toString(array1)); //from w ww . j a v a 2s. c om array1 = doubleArraySize(array1); System.out.println("New size: " + array1.length); System.out.println(Arrays.toString(array1)); } public static int[] doubleArraySize(int original[]) { int length = original.length; int newArray[] = new int[length*2]; System.arraycopy(original, 0, newArray, 0, length); return newArray; } }