A more efficient enqueue algorithm in Java So I have this simple code in Java. It enqueue (adds) and element to the end of the queue (implemented by an ArrayList) without changing the original queue.

public class MyQueue&lt;T&gt;{
    private List&lt;T&gt; body;

    // some constructors and helper functions.

    //copy constructor
    public MyQueue(List&lt;T&gt; list){
        this.body = list;
    }

    //this is the function
    public MyQueue&lt;T&gt; enqueue(T obj){
        List&lt;T&gt; temp = new ArrayList&lt;T&gt;(body);
        temp.add(obj);
        return new Queue&lt;T&gt;(temp);
    }


The whole idea is to make enqueue faster and more efficient, and again, as you notice, without changing the value of the original queue.  Any ideas?

UPDATE 
For the sake of completing the idea. 

1- This is an assignment so university, the skeleton provided is not to be changed, the task is to make the function enqueue faster (i do realize i am copying twice and thats the slow part).

2- As for the helper functions, they are simple:

public T peek(){
if(body.isEmpty()){
   thrown new NoSuchElementException();
}
return body.get(0);
}

public int size(){
return body.size();
}
It seems like what you are trying to accomplish here is to make your Queue class immutable. That in itself is good, but there are a couple of issues with your approach:


Creating a new class for this is not needed. There already exists classes for that. Use Collections.unmodifiableList to create one.
Your class does not implement the List interface (or the Queue interface for that matter). I guess there is a way to access the embedded List&lt;T&gt; such as getList hidden among "some constructors and helper functions", but if all that does is to return this.body; then your entire list is still accessible and modifiable.
The List&lt;T&gt; body field could be, and should be, declared final.


Instead of your entire Queue class, you might want to use this static method:

public static &lt;E&gt; List&lt;E&gt; addToList(List&lt;E&gt; oldList, E newElement) {
    List&lt;E&gt; temp = new ArrayList&lt;E&gt;(oldList);
    temp.add(newElement);
    return Collections.unmodifiableList(temp);
}


I should add however, that there is a difference between an unmodifiable list and what I understood about your approach. An unmodifiable list in Java does not allow any change to the list at all, such as list.set(index, obj).