【发布时间】:2019-07-12 10:01:04
【问题描述】:
我想把这个程序的数组变成一个ArrayList。到目前为止我知道数组会变成
ArrayList<StudentList> list = new ArrayList<StudentList>();
每个list[i]都会变成:
list.get(i)
但是我不确定以下行将是什么以满足 ArrayList 版本
list[i] = new StudentList();
所以这里是完整的代码:
public static void main(String[] args) {
StudentList[] list = new StudentList[5];
int i;
for (i = 0; i < list.length; ++i) {
list[i] = new StudentList();
System.out.println("\nEnter information of Student _" + (i + 1) + "\n");
list[i].DataUserPrompt();
}
for (i = 0; i < list.length; ++i) {
list[i].DisplayStudentData();
}
File file12 = new File("s_records.txt");
try {
PrintWriter output = new PrintWriter(file12);
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
【问题讨论】: