I am coding for my Applictation , i came across a requirement , where i needed to convert a String to char array I
String str_a = "Testing";
char c[] = str_a.toCharArray();
for (char d : c) {
System.out.println(d);
}
As i did not initialize the char c[]
My question is why it doesn’t throw a NullPointerException, typically this should be done this way
char[] char_array = new char[str_a.length()];
char_array = str_a.toCharArray();
for (char d : c) {
System.out.println(d);
}
The source code of
toCharArray():