我编写了我的应用程序,我遇到了一个要求,我需要将String转换为char数组I.
String str_a = "Testing";
char c[] = str_a.toCharArray();
for (char d : c) {
System.out.println(d);
}
Run Code Online (Sandbox Code Playgroud)
因为我没有初始化 char c[]
我的问题是为什么它不抛出NullPointerException,通常这应该这样做
char[] char_array = new char[str_a.length()];
char_array = str_a.toCharArray();
for (char d : c) {
System.out.println(d);
}
Run Code Online (Sandbox Code Playgroud)