Java 数组扩容
在数组初始化后对数组进行扩容
public class Main { public static void main(String[] args) { String[] names = new String[] { "A", "B", "C" }; String[] extended = new String[5]; extended[3] = "D"; extended[4] = "E"; System.arraycopy(names, 0, extended, 0, names.length); for (String str : extended){ System.out.println(str); } } }
编译运行以上 Java 代码,输出结果如下
A B C D E