日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

数组的复制

發布時間:2025/6/15 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 数组的复制 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?數組復制有以下幾種方法:

  • 通過for循環進行數值復制
  • 源數組名.clone()
  • public static native void arraycopy(Object src,? int? srcPos,Object dest, int destPo, int length);(System類方法)
  • ?public static int[] copyOf(int[] original, int newLength)?? (Arrays類方法)
  • ?public static int[] copyOfRange(int[] original, int from, int to)? (Arrays類方法)
  • 示例代碼

    package array;import java.util.Arrays;public class arrayCopy {/*** @jeasion Array Copy */public static void main(String[] args) {int[] a= new int[10];int[] b= new int[5];for(int i=0;i<10;i++){a[i]=(int)(Math.random()*10+1);}for(int j:a){System.out.print("\t@a:"+j);}System.out.println("\n賦值");//@1 數組賦值for(int i=3;i<8;i++){b[i-3]=a[i];}for(int j:b){System.out.print("\t@1:"+j);}System.out.println("\nclone()");//@2 數組克隆 array.clone()b=a.clone();for(int j:b){System.out.print("\t@2:"+j);}System.out.println("\nSystem.arraycopy()");//@3 System.arraycopy(source,first,aim,index,length);System.arraycopy(a,3,b,0,5);for(int j:b){System.out.print("\t@3:"+j);}System.out.println("\nArraycopyOf()");//@4 Arrays.copyOf(source,length) --Of 為大寫 length是新數組的長度,可以比原數組長//Arrays。copyOf(source,source。length+mount) 可以實現原數組長度的擴充b=Arrays.copyOf(a, 5);for(int j:b){System.out.print("\t@4:"+j);}System.out.println("\nArray.copyRanger()");//@5 Arrays.copyRange();b=Arrays.copyOfRange(a, 3, 7);for(int j:b){System.out.print("\t@5:"+j);}}}

    示例結果

    @a:1 @a:10 @a:8 @a:3 @a:2 @a:8 @a:10 @a:8 @a:3 @a:2 賦值@1:3 @1:2 @1:8 @1:10 @1:8 clone()@2:1 @2:10 @2:8 @2:3 @2:2 @2:8 @2:10 @2:8 @2:3 @2:2 System.arraycopy()@3:3 @3:2 @3:8 @3:10 @3:8 @3:8 @3:10 @3:8 @3:3 @3:2 ArraycopyOf()@4:1 @4:10 @4:8 @4:3 @4:2 Array.copyRanger()@5:3 @5:2 @5:8 @5:10

    ?

    轉載于:https://www.cnblogs.com/jeasion/p/10758355.html

    《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

    總結

    以上是生活随笔為你收集整理的数组的复制的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。