How do you set one array's values to another array's values in Java?

后端 未结 2 1990
感动是毒
感动是毒 2021-02-03 13:13

Lets say you had two arrays:

    int[] a = {2, 3, 4};
    int[] b = {4, 5, 6};

How would you set array a to array b and keep them different dif

2条回答
  •  逝去的感伤
    2021-02-03 13:30

    For arrays, take a look at:

    • System.arraycopy();
    • Arrays.copyOf() and Arrays.copyOfRange();
    • Object.clone().

    For ArrayList:

    • ArrayList.clear() and ArrayList.addAll();
    • ArrayList.ArrayList(Collection c);
    • Object.clone().

    I think this should give you enough pointers to make progress with your homework.

提交回复
热议问题