package notebook;
import java.util.ArrayList;
public class NoteBook {
private ArrayListnotes= new ArrayList();
public void add(String r) {
notes.add(r);
}
public void add (String r ,int location) {
notes.add(location,r);
}
public int getsize() {
return notes.size();
}
public String getnote(int index) {
return notes.get(index);
}
public void remove(int index) {
notes.remove(index);
}
public String[] list() {
String [] a= new String[notes.size()];
for (int i=0;i<notes.size();i++) {
a[i]=notes.get(i);
}
return a;
}
String []x=new String[10];
for (int i=0;i<x.length;i++) {
x[i]=""+i;
}
System.out.println(x[10]);
}
}请问为何最后这几行的运行之后会超出length
String []x=new String[10];定义了10个元素,而不是定义到x[10],因为是从0开始索引的,所以最大的下标是9
x[10]越界了
最大下标是9