copying array by value in java

前端 未结 5 1028
轻奢々
轻奢々 2020-12-19 00:42

I tried to make an independent copy of an array but couldnt get one. see i cannot copy it integer by integer using a for loop because of efficiency reasons. Is there any oth

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-19 01:19

    Look at System.arraycopy() method. Like,

    int[] b = new int[a.length];
    System.arraycopy(a, 0, b, 0, a.length);
    

提交回复
热议问题