要复制包含多个元素的数组,请使用系统.arraycopy() http://download.oracle.com/javase/6/docs/api/java/lang/System.html#arraycopy%28java.lang.Object,%20int,%20java.lang.Object,%20int,%20int%29,因为它通常作为本机代码实现,例如Sun 的VM 使用手工编码的汇编程序。
前 > 后
由于数据是连续的,因此它可以保留在新数组中的同一位置。
System.arraycopy(oldArray, front, newArray, front, front-rear);
前
数据是不连续的,因此将两个块复制到新数组的开头。
// copy [rear to end]
System.arraycopy(oldArray, rear, newArray, 0, oldArray.length-rear);
// copy [0 to front]
System.arraycopy(oldArray, 0, newArray, oldArray.length-rear, front);
front = oldArray.length-(rear-front);
rear = 0;