views:

291

answers:

3

Is there any collection class in java, that implements push_back() and push_front() methods?

+1  A: 

The List appears to with both add functions.

http://java.sun.com/j2se/1.4.2/docs/api/java/util/List.html

Daniel A. White
Hmm, List is an interface and both variants of add are specifically marked as optional, throwing UnsupportedOperationException if the add method is not supported by the concrete class. It happens that all known implementing classes support both variants but not necessarily all user-defined ones. You might want to make that clear.
paxdiablo
+2  A: 

The class java.util.LinkedList has addFirst/Last(), getFirst/last() and removeFirst/Last().

Jerome
push_back() = addLast(), push_front() = addFirst().
Cipi
+5  A: 

Any collection that implements Deque should have it (ArrayDeque, LinkedList)

fn
This exists only in Java 6.
Jerome
@Jerome, in the absence of a request for a specific version, I think it's okay to assume that an answer can assume any version. You could just as easily complain that your answer requires 1.2 :-)
paxdiablo
It wasn't a complaint, just an information.
Jerome