菜鸟教程java第二十二篇

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);
        }
    }
}

 

posted @ 2021-11-23 15:17  zrswheart  阅读(27)  评论(0编辑  收藏  举报