public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length) Parameters: src - the source array. srcPos - starting position in the source array. dest - the destination array. destPos - starting position in the destination data. length - the number of array elements to be copied. Throws: IndexOutOfBoundsException - if copying would cause access of data outside array bounds. ArrayStoreException - if an element in the src array could not be stored into the dest array because of a type mismatch. NullPointerException - if either src or dest is null.
public class AcceptInMessage { public static void main(String[] args) { char[] engChar = {'a','b','c','d','e','f','g','h','i','j','k','l','m', 'n','o','p','q','r','s','t','u','v','w','x','y','z'}; char[] arcChar = {'v','w','x','y','z'};
{
public static void main(String[] args)
{
char engChar[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m',
'n','o','p','q','r','s','t','u','v','w','x','y','z'};
char arcChar[] = new char[26];
System.out.println(engChar.length);
System.arraycopy(engChar,0,arcChar,0,5);
for(int i=0;i<=25;i++)
{
System.out.print(engChar[i]);
}
System.out.println();
}
}
这样就可以执行了,可能两个原因1、数组长度为0,2、数组类型不同
int srcPos,
Object dest,
int destPos,
int length)
Parameters:
src - the source array.
srcPos - starting position in the source array.
dest - the destination array.
destPos - starting position in the destination data.
length - the number of array elements to be copied.
Throws:
IndexOutOfBoundsException - if copying would cause access of data outside array bounds.
ArrayStoreException - if an element in the src array could not be stored into the dest array because of a type mismatch.
NullPointerException - if either src or dest is null.
{
public static void main(String[] args)
{
char[] engChar = {'a','b','c','d','e','f','g','h','i','j','k','l','m',
'n','o','p','q','r','s','t','u','v','w','x','y','z'};
char[] arcChar = {'v','w','x','y','z'};
System.out.println(engChar.length);
try {
System.arraycopy(engChar,0,arcChar,0,3);
}
catch (Exception e) {
e.printStackTrace();
}
finally {
for(int i=0;i<arcChar.length;i++)
{
System.out.print(arcChar[i]);
}
}
}
}
执行
26
abcyz数组类型要相同,长度可以不同