数组拷贝方法之Arrays.copyOf(),Arrays.copyOfRange()

1、Arrays.copyOf()接收两个参数,其一是拷贝的数组,其二为数组长度

2、Arrays.copyOfRange()接收三个参数,分别是拷贝的数组,开始位置,结束位置(不包含该位置)

public class CopyTest {

	void printByte(byte[] btCopy) {
		for(byte b:btCopy) {System.out.print(b);}
	}
        void printByte1(byte[] btCopy1) {
		for(byte b:btCopy1) {System.out.print(b);}
	}
    
        public static void main(String args[]) {
    	
    	byte[] bt = new byte[] {1,2,3,4,5};
    	byte[] btCopy = Arrays.copyOf(bt, bt.length);
    	byte[] btCopy1 = Arrays.copyOfRange(bt, 0, bt.length);
    	
    	new CopyTest().printByte(btCopy);
    	System.out.println(" ");
    	new CopyTest().printByte(btCopy1);
    	
    }

}

 

你可能感兴趣的:(数组拷贝方法之Arrays.copyOf(),Arrays.copyOfRange())