数组拷贝Arraycopy

package qing;
//数组拷贝
public class Arraycopy {
	public static void main(String[]args){
		//一维数组拷贝
		String a[]={"小米","华为","阿里","腾讯","百度"};
		String []aBak=new String[6];
		//从a数组第0个copy到数组aBak 0个开始,长度是a数组长度
		System.arraycopy(a, 0, aBak, 0, a.length);
		for(int i=0;i<aBak.length;i++){
			System.out.print(aBak[i]+"  ");
		}
		System.out.println();
		//二维数组拷贝
		int intArray[][]={{1,2},{1,2,3},{3,4}};
		int intArraybak[][]=new int[3][];
		System.arraycopy(intArray, 0, intArraybak, 0, intArray.length);
		for(int i=0;i<intArray.length;i++){
			for(int j=0;j<intArray[i].length;j++){
				System.out.println(intArraybak[i][j]+"  ");
			}	System.out.println();
		}	
			
	}
}



你可能感兴趣的:(Arraycopy,java)