package cn.edu.bjut.chapter5; public class ExpandArray { static int[] expand(int[] m) { int[] n = new int[m.length * 2]; for (int j = 0; j < m.length; j++) { n[j] = m[j]; } return n; } static int[] expand2(int[] m) { int[] n = new int[m.length * 2]; System.arraycopy(m, 0, n, 0, m.length); return n; } public static void main(String[] args) { int[] a = new int[] { 4, 6, 8, 32 }; int[] b = expand(a); int[] c = expand2(a); for (int i = 0; i < b.length; i++) { System.out.println(b[i]); } for (int i = 0; i < c.length; i++) { System.out.println(c[i]); } } }