Originally posted by Joe Ess: I'm a fan of using System.arrayCopy to accomplish this task.
'Twould be nice, but it doesn't actually work:
The Javadoc says that you can only copy across different-type arrays if the assignment across the two types can be made by "assignment conversion" -- i.e., without a cast. So you could do it in the other direction (byte to int) but not int to byte.
If you want to convert each int to four bytes and thus ensure no lost info, you can use a DataOutputStream wrapped around a ByteArrayOutputStream. Loop through each int in the array and use writeInt() - it will be writtenas four bytes, high byte first. When done, use toByteArray() to get the complete array. If / when you want to read the values back into ints later, just use a DataInputStream, which has a readInt() method.