以下實例示範如何在陣列初始化後對陣列進行擴容:
/* 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)!