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

后端 未结 2 1989
感动是毒
感动是毒 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:35

    You may want to use clone:

    a = b.clone();
    

    or use arraycopy(Object source, int sourcePosition, Object destination, int destinationPosition, int numberOfElements)

    System.arraycopy(b, 0, a, 0, b.length());
    

提交回复
热议问题