I am receiving a packet with byte array via UDP in Java.
I know the maximum possible byte size, but I don’t know currently received size.
If I create a String instance from this byte array, then the string will have lots and lots of NUL characters (\u0000) after the useful payload.
How do I convert this byte array to String up to a point when the first NUL appears?
(I do not expect to have NUL in my payload).
Don’t create the
Stringfrom the whole thing. Scan the byte array for the zero, and then call