先说结论:
字符串初始化为:""
字符串数组初始化为:"null"
整型数组初始化为:0
测试代码:
import java.util.*; public class 字符串数组初始化 { public static void main(String[] args) { //字符串数组初始值为null,null,null,null String[] arr = new String[4]; int[] arrInt = new int[4]; System.out.println("从这里开始输出"); //字符串数组无法初始化为"" for(String s:arr){ s=new String(); System.out.print("字符串:"+s+" "); System.out.print("字符数组:"+arr[0]+" "); System.out.print("数组:"+arrInt[0]+" "); //arr[0]==s False } } }
首先看输出:
之后看一下调试: