Java Array class copyOf(byte[] original, int newLength) example
Array class copyOf(byte[] original, int newLength) method example
Array class copyOf(byte[] original, int newLength)method example. This example shows you how to use copyOf(byte[] original, int newLength)method.This method Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.
Here is the code:-
/**
* @Program that Copies the specified array, truncating or padding with zeros
* (if necessary) so the copy has the specified length.
* Copy1Array.java
* Author:-RoseIndia Team
* Date:-15-May-2008
*/
import java.util.*;
public class Copy1Array {
public static void main(String[] args) {
//creating a byte array
byte b[]={1,2,3,4,5,6,7,8};
//Copies the specified byte array,
byte b1[]=Arrays.copyOf(b,9);
for (int i=0;i<b1.length;i++)
System.out.println("The Copied Byte array is:-" + b1[i]);
}
} |
Output of the program:-
The Copied Byte array is:-1
The Copied Byte array is:-2
The Copied Byte array is:-3
The Copied Byte array is:-4
The Copied Byte array is:-5
The Copied Byte array is:-6
The Copied Byte array is:-7
The Copied Byte array is:-8
The Copied Byte array is:-0 |
|