I implemented both add()
and remove()
methods from my ArrayList
Class.
public void add(Object obj) {
if(data.length - currentSize <= 5) {
increaseListSize();
}
data[currentSize++] = obj;
}
public Object remove(int index){
if(index < currentSize){
Object obj = data[index];
data[index] = null;
int tmp = index;
while(tmp < currentSize){
data[tmp] = data[tmp+1];
data[tmp+1] = null;
tmp++;
}
currentSize--;
return obj;
} else {
throw new ArrayIndexOutOfBoundsException();
}
}
However, I don't know how to remove the specific index of my ArrayList
of members
.
if(temp[0].equals("ADD")) {
memberList.add(member);
fileOut.writeLine(member.toString());
fileLog.writeLine("New member " + member.toString() + " was succesfully added");
}
**else if(temp[0].equals("REMOVE")) {
//memberList.remove(index)
}**
}
Is there any suggestion of how should I get to remove the index of an object of the memberList
? Can I modify my remove()
method so that I could directly remove the object instead?