回覆列表
  • 1 # naptk41254

    publicclassListInsert{publicstaticlong[]insert(long[]arr,inti,longl){//新建陣列,對原陣列擴容long[]arr1=newlong[arr.length+1];//將原陣列資料賦值給新陣列for(intj=0;j<arr.length;j++){arr1[j]=arr[j];}//將大於i的資料向後移動一位for(intj=arr1.length-2;j>i;j--){arr1[j+1]=arr1[j];}//賦值到i位置arr1[i+1]=l;returnarr1;}//測試publicstaticvoidmain(String[]args){long[]arr={12,25,11,36,14};long[]arr1=insert(arr,2,100);for(longl:arr1){System.out.print(l+"");}}陣列的擴容方式:arr=Arrays.copyOf(arr,arr.length+1);

  • 中秋節和大豐收的關聯?
  • 女人左邊嘴唇上方長痣有什麼意思?