I have this method I'm trying to the return is the student that will be removed and then remove student at pos
I tried almost everything I put the return outside the if statment , but I still get error I also tried to substract 1 from the size but I still get error. the error is arrayIndexOutOfBound it said index 4 and size 4 .. what should I do
public Student removeStudentAt(int index) {
Student stu = list.get(index);
if (index < 0 || index > list.size) {
return null;
} else {
list.remove(index);
return stu;
}
}
my next problem is
I have class school extend students and the class that I'm writing the code in is 'AllSchool' it have arrayList of type school and I'm trying to create string of array to with the full name of all the students and return the array of the student(full names)
students class have these attribute
private String fName;
private String sName;
private int id;
I have get and set method for the attribute and getfullName method
I'm not sure what I did wrong ,but here is what I did
The error that I got is array length differed expected length 7 actuak kength 8
public String[] getAllNames() {
String[] allNames = new String[size()];
int i = allNames.length;
int n = ++i;
String[] copyArray = new String[n];
for (int j = 0; j < allNames.length; j++) {
copyArray[j] = allNames[j];
}
return copyArray;
}
how can I fix my code .. did I miss something ?