📌  相关文章
📜  如何将元素添加到数组的末尾java代码示例

📅  最后修改于: 2022-03-11 14:52:48.296000             🧑  作者: Mango

代码示例1
public static void main(String[] args) {
    int[] array = new int[] {1, 2, 3};
    System.out.println(Arrays.toString(array));
    array = Arrays.copyOf(array, array.length + 1); //create new array from old array and allocate one more element
    array[array.length - 1] = 4;
    System.out.println(Arrays.toString(array));
}