Is there a way to convert a fixed size byte array to a String without iterating over the byte array to find where the String ends? The problem I'm having is that not all of the bytes in the byte array are characters. I'm padding the end of the array with 0
. If I use new String(byte[])
, it interprets the 0
s as part of the string. Is there a certain character I can pad the byte[] with and not have it interpret it as part of the String?
| |||||
feedback
|
There's a String constructor that takes a | |||
feedback
|
No, since all byte values are valid characters in a string. You must keep track of the count of valid bytes, and use the If you don't want to keep track of the count manually (perhaps because you are building the byte array piecemeal), consider using a | |||
feedback
|