Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - Byte[] to byte[]

There is Vector and DataOutputStream. I need to write bytes from Vector (toArray returns Byte[]) to the stream, but it understands byte[] only. How to convert Byte[] to byte[] ?

like image 242
artem Avatar asked Jun 21 '11 19:06

artem


People also ask

What is byte [] in Java?

A byte in Java is 8 bits. It is a primitive data type, meaning it comes packaged with Java. Bytes can hold values from -128 to 127. No special tasks are needed to use it; simply declare a byte variable and you are off to the races.

How do I combine byte arrays?

The recommended solution to concatenate two or more byte arrays is using ByteArrayOutputStream . The idea is to write bytes from each of the byte arrays to the output stream, and then call toByteArray() to get the current contents of the output stream as a byte array.

Can we add byte and byte in Java?

The addition of two-byte values in java is the same as normal integer addition. The byte data type is 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive).

How do you assign a byte array in Java?

Arrays. fill(). This method assigns the required byte value to the byte array in Java.


1 Answers

You could use the toPrimitive method in the Apache Commons lang library ArrayUtils class?

like image 172
tim_yates Avatar answered Oct 06 '22 09:10

tim_yates