public void addStudent(String student) {
String [] temp = new String[students.length * 2];
for(int i = 0; i < students.length; i++){
temp[i] = students[i];
}
students = temp;
students[numberOfStudents] = student;
numberOfStudents++;
}
public String[] getStudents() {
String[] copyStudents = new String[students.length];
return copyStudents;
}
我试图让 getStudents 方法返回我在 addStudent 方法中创建的数组的副本。我不知道该怎么做。