Java strings - null terminated

About

Java strings are not terminated with a null characters as in C or C++.

However, when working with Jdbc, you can get Java String that are Null terminated.

Snippet

// By getting the bytes, the null character goes away
// Character nullCharacter = '\u0000';
byte[] bytes = stringWithNullTermination.getBytes();
Charset charSet = Charset.forName("UTF-8");
stringWithoutNullTermination = new String(bytes , 0, bytes.length, charSet);

Documentation / Reference


Powered by ComboStrap