Java: System.arraycopy is not copying my arrays -


i have array called "first" , array called "second", both arrays of type byte , size of 10 indexes.

i copying 2 arrays 1 array called "third" of type byte , of length 2*first.length follow:

byte[] third= new byte[2*first.length]; for(int = 0; i<first.length;i++){     system.arraycopy(first[i], 0, third[i], 0, first.length);     }    for(int = 0; i<second.length;i++){     system.arraycopy(second[i], 0, third[i], first.length, first.length);     } 

but not copying , throws exception: arraystoreexception

i read on here exception thrown when element in src array not stored dest array because of type mismatch. arrays in bytes there no mismatch

what problem ?

you pass system.arraycopy array, not array element. passing first[i] arraycopy first argument, you're passing in byte, (because arraycopy declared accepting object src argument) gets promoted byte. you're getting arraystoreexception first reason in list in the documentation:

...if of following true, arraystoreexception thrown , destination not modified:

the src argument refers object not array.

here's how use arraycopy copy 2 byte[] arrays third:

// declarations `first` , `second` clarity byte[] first = new byte[10]; byte[] second = new byte[10]; // ...presumably fill in `first` , `second` here...  // copy `third` byte[] third = new byte[first.length + second.length]; system.arraycopy(first,  0, third, 0, first.length); system.arraycopy(second, 0, third, first.length, second.length); 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -