I'm practcing for my test and I couldn't solve these questions I spent hours trying to solve it but every time I get error
ArrayList<objClass> li = new ArrayList<>();
public objClass RemoveAtPos(int pos){
// I'm trying to remove the object at the given pos , but first I want to check if the pos is out of range
//if it out of range then return null otherwise remove the object and return the object that was removed
//here is what I did
if (pos >= li.size() || pos < 0) {
return null;
} else {
li.remove(pos);
}
return li.get(pos);
// when I test the method I get IndexOutOfBoundsException
}
//also in the same class I have
public String[] getAllElementInArr() {
//I'm not sure how to this how can I get all the element in the li and store it in String of array
}