I need to convert String[]
to Byte[]
in Java. Essentially, I have a space delimited string returned from my database. I have successfully split this String into an array of string elements, and now I need to convert each element into a byte, and produce a byte[] at the end.
So far, the code below is what I have been able to put together but I need some help making this work please, as the getBytes() function returns a byte[] instead of a single byte. I only need a single byte for the string (example string is 0xd1 )
byte[] localbyte = null;
if(nbytes != null)
{
String[] arr = (nbytes.split(" "));
localbyte = new byte[arr.length];
for (int i=0; i<localbyte.length; i++) {
localbyte[i] = arr[i].getBytes();
}
}