// 静态数组
Boolean[] a = new Boolean[2]; //Boolean封装了基本类型boolean,同理还有...
System.out.println("数组元素默认值是(如果new后面的数组元素类型是引用类型,则默认值是null;" +
"如果new后面的数组元素类型是基本类型,则是0或0.0或false):");
System.out.println(a[0]);
System.out.println(a[1]);
a[0] = false;
a[1] = true;
System.out.println("数组元素赋值后的值是:");
System.out.println(a[0]);
System.out.println(a[1]);
String[] b = new String[]{"one", "tow"};
System.out.println(b[0]);
System.out.println(b[1]);
String[] c = new String[]{"one", "tow"};
System.out.println(c[0]);
System.out.println(c[1]);
System.out.println("静态数组长度:" + c.length);
// 数组不能下标越界:Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
//System.out.println(c[2]);
// 遍历数组
for (int i = 0; i < c.length; i++) {
System.out.println(c[i]);
}
for (String item:c) {
System.out.println(item);
}
}
java静态数组
于 2023-05-27 09:23:25 首次发布