以下实例演示了如何在数组初始化后对数组进行扩容:
/* author by w3cschool.cc 文件名:Main.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); } }}
以上代码运行输出结果为:
A B C D E
以上就是Java 实例 - 数组扩容的内容,更多相关内容请关注PHP中文网(m.sbmmt.com)!