62,614
社区成员
发帖
与我相关
我的任务
分享
// 创建长度为5的String对象数组
// 这5个引用默认都是null,即不指向任何对象
String[] strarr = new String[5];
for (int i = 0; i < 5; i++)
System.out.print(strarr[i] + " ");
System.out.println();
// 让这5个引用指向新创建的String对象
for (int i = 0; i < 5; i++)
strarr[i] = new String("str" + i);
for (int i = 0; i < 5; i++)
System.out.print(strarr[i] + " ");
程序输出:
null null null null null
str0 str1 str2 str3 str4