今天在使用for初始化的时候发生了问题,这里记录一下
for(;;){
}
可以很好的初始化一个数组,举例如下
String[] tempList1 = new String[100]; for(int i = 0 ;i < tempList1.length; i++){ tempList1[i] = "num" + i;}
ok
出现问题的模式是for的高级封装法,
for(:){
}
这种方法只能用来遍历,如果用来初始化,会出现问题,
String[] tempList1 = new String[100]; // for(int i = 0 ;i < tempList1.length; i++){ // tempList1[i] = "num" + i; // } for(String i : tempList1){ i = "num"; }error这里的i是新建的一个引用。
初始化完成之后,数组中内容依然为null