Manually manipulating ArrayList

Posted by jsan on Stack Overflow See other posts from Stack Overflow or by jsan
Published on 2012-10-19T16:17:40Z Indexed on 2012/10/19 17:01 UTC
Read the original article Hit count: 115

Filed under:
|

I have an assignment where I have to create a deque, however I am not allowed to use any built-in classes or interfaces. I am implementing my deque using an array list. My problem is that when I have to, for instance, add to the beginning of the array list (beginning of the queue), i am not allowed to do this:

public void addFirst(ArrayList<Integer> array) 
{
    array.add(0, int);
}

Is there a way to do this without using the add() function? Such as manually adding to the front and shifting the rest of the array to the right? Or maybe creating a new array list and copying...I'm not sure. Any help would be great; I have a bunch of functions to write, and getting the first one done will definitely put me in the right direction. Thanks

© Stack Overflow or respective owner

Related posts about java

Related posts about arraylist