Quantcast
Channel: How to convert byte[] to Byte[] and the other way around? - Stack Overflow
Browsing latest articles
Browse All 10 View Live

Answer by dani77 for How to convert byte[] to Byte[] and the other way around?

Since Java 8:byte[] bytes = new bytes[byteObject.length];IntStream.range(0, byteObject.length).forEach(x -> bytes [x] = byteObject[x]);

View Article



Answer by David Urry for How to convert byte[] to Byte[] and the other way...

Step back. Look at the bigger picture. You're stuck converting byte[] to Byte[] or vice versa because of Java's strict type casing with something like thisList< Byte>orList<Byte[]>Now you...

View Article

Answer by mkalmo for How to convert byte[] to Byte[] and the other way around?

If someone preferes Stream API over ordinary loops.private Byte[] toObjects(byte[] bytes) { return IntStream.range(0, bytes.length) .mapToObj(i -> bytes[i]) .toArray(Byte[]::new);}

View Article

Answer by LaCrampe for How to convert byte[] to Byte[] and the other way around?

byte[] to Byte[] :byte[] bytes = ...;Byte[] byteObject = ArrayUtils.toObject(bytes);Byte[] to byte[] :Byte[] byteObject = new Byte[0];byte[] bytes = ArrayUtils.toPrimitive(byteObject);Note: ArrayUtils...

View Article

Answer by ajb for How to convert byte[] to Byte[] and the other way around?

Java 8 solution:Byte[] toObjects(byte[] bytesPrim) { Byte[] bytes = new Byte[bytesPrim.length]; Arrays.setAll(bytes, n -> bytesPrim[n]); return bytes;}Unfortunately, you can't do this to convert...

View Article


Answer by jacktrades for How to convert byte[] to Byte[] and the other way...

byte[] toPrimitives(Byte[] oBytes){ byte[] bytes = new byte[oBytes.length]; for(int i = 0; i < oBytes.length; i++){ bytes[i] = oBytes[i]; } return bytes;}Inverse://byte[] to Byte[]Byte[]...

View Article

Answer by Giannis for How to convert byte[] to Byte[] and the other way around?

You could use the toPrimitive method in the Apache Commons lang library ArrayUtils class,As suggested here - Java - Byte[] to byte[]

View Article

Answer by DNA for How to convert byte[] to Byte[] and the other way around?

From byte[] to Byte[]: byte[] b = new byte[]{1,2}; Byte[] B = new Byte[b.length]; for (int i = 0; i < b.length; i++) { B[i] = Byte.valueOf(b[i]); }From Byte[] to byte[] (using our previously-defined...

View Article


Answer by Juvanis for How to convert byte[] to Byte[] and the other way around?

Byte class is a wrapper for the primitive byte. This should do the work:byte[] bytes = new byte[10];Byte[] byteObjects = new Byte[bytes.length];int i=0; // Associating Byte array values with bytes....

View Article


How to convert byte[] to Byte[] and the other way around?

How to convert byte[] to Byte[] and also Byte[] to byte[], in the case of not using any 3rd party library?Is there a way to do it fast just using the standard library?

View Article
Browsing latest articles
Browse All 10 View Live


Latest Images