Java strings - null terminated

> Procedural Languages > Java

1 - 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.

2 - 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);

3 - Documentation / Reference

lang/java/null_terminated.txt · Last modified: 2019/11/13 19:12 by gerardnico