I am trying to replicate this in Java. To save your click, it says that the character-to-character ['F', 'R', 'A', 'N', 'K', NULL, 'k', 'e', 'f', 'w']when it is converted to a zero-terminated string will stop afterwards 'K', since there is a null pointer there. However, my Java attempts do not seem to work.
public class TerminatingStrings{
public static void main(String[] args){
char[] broken = new char[3];
broken[0] = 'a';
broken[1] = '\u0000';
broken[2] = 'c';
String s = new String(broken);
System.out.println(s);
}
}
Prints ac. Besides this, I also tried (1) not to initialize broken[1]and (2), explicitly setting it to null, in an attempt that did not even compile.
Is this even possible in Java? Or maybe my understanding of things is wrong?
source
share