I need to add elements to an ArrayList
queue whatever, but when I call the function to add an element, I want it to add the element at the beginning of the arra
You can use
public List addToListStart(List list, E obj){
list.add(0,obj);
return (List)list;
}
Change E with your datatype
If deleting the oldest element is necessary then you can add:
list.remove(list.size()-1);
before return statement. Otherwise list will add your object at beginning and also retain oldest element.
This will delete last element in list.