I have an array called "first" and another array called "second", both arrays are of type byte and size of 10 indexes.
I am copying the two arrays into one array called "third" of type byte too and of length 2*first.length as follow:
byte[] third= new byte[2*first.length];
for(int i = 0; i<first.length;i++){
System.arraycopy(first[i], 0, third[i], 0, first.length);
}
for(int i = 0; i<second.length;i++){
System.arraycopy(second[i], 0, third[i], first.length, first.length);
}
but it is not copying and it throws an exception: ArrayStoreException
I read on the here that this exception is thrown when an element in the src array could not be stored into the dest array because of a type mismatch. but all my arrays are in bytes so there is no mismatch
what exactly is the problem ?
arraycopy. The other way around,arraycopyis not required if you use a loop because you're assigning the values yourself.