【Java基础】System的arraycopy方法拷贝数组
一、在System类中查看方法的定义
二、示例
1 public class SystemArrayCopyTest { 2 3 /** 4 * @Description: System的arrayCopy方法测试 5 * @param @param args 6 * @return void 7 * @throws 8 * @author liping.sang 9 * @date 2017-6-21 10 */ 11 private static int COPY_LENTH=3; 12 public static void main(String[] args) { 13 String [] src = {"Do","More","Think","More"}; 14 String [] dest= new String[COPY_LENTH]; 15 System.arraycopy(src, 0, dest, 0, COPY_LENTH); 16 for(String s:dest){ 17 System.out.print(s+" "); 18 } 19 System.out.println(); 20 System.out.println("----------------自身拷贝-----------------"); 21 System.arraycopy(src, 0, src, 1, COPY_LENTH-1); 22 for(String s:src){ 23 System.out.print(s+" "); 24 } 25 } 26 27 }
Do More Think ----------------自身拷贝----------------- Do Do More More