Deleting the first occurrence of a target in aList [closed]
- by Bandz Jooz
/** Replaces each occurrence of oldItem in aList with newItem */
public static void replace(List<Student> aList, Student oldItemStudent newItem) {
int index = aList.indexOf(oldItem);
while(index != -1){
aList.set(index, newItem);
index = aList.indexOf(oldItem);
}
/** Deletes the first occurrence of target in aList */
public static void delete(List<Student> aList, Student target){
Object o = //stuck here, dont know how to set up boolean stuff
}
}
I figured out how to do the first method by looking up Java documentation, however I can't figure out how to finish my code for the second method even though I looked up the documentation which states:
boolean remove(Object o)
Removes the first occurrence of the specified element from this list, if it is present.