java 數組操作方法

來源:互聯網
上載者:User

標籤:名稱   操作   數組   數組名   string   style   array   public   ++   

數組操作方法:

 

實現數組拷貝:

文法:System.arraycopy(源數組名稱,源數組拷貝開始索引,目標數組名稱,目標數組拷貝數組索引,長度)

 

  • 數組A:1 、 2 、 3 、 4 、 5 、 6 、 7 、 8  ;
  • 數組B:11 、 22 、 33 、 44 、 55 、 66 、 77 、 88  ;

  目標數組:11 、 22 、 4 、 5 、6 、 66 、 77 、 88 ;

 1 public class demo { 2     public static void main(String[] args) { 3     int dataA [] = new int[]{1,2,3,4,5,6,7,8}; 4     int dataB [] = new int[]{11,22,33,44,55,66,77,88}; 5     System.arraycopy(dataA,3,dataB,2,3); 6     getprint(dataB); 7     } 8     //列印出數組 9     public static void getprint(int array[]){10         for (int i = 0 ; i < array.length ; i++) {11             System.out.print(array[i] + "、");12         }13     }14 }

 

實現數組排序:

文法:java.util.Arrays.sort(數組名稱) ;

 

 1 public class demo { 2     public static void main(String[] args) { 3         int data[] = new int[]{11,559,1894,71,69,181,78,156,41,126,13}; 4         java.util.Arrays.sort(data); 5         getprint(data); 6     } 7     public static void getprint(int array []){ 8         for (int i =0 ; i < array.length ; i++) { 9             System.out.print(array[i]+"、");10         }11     }12 }

 

java 數組操作方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.