Is there any collection class in java, that implements push_back()
and push_front()
methods?
views:
291answers:
3Hmm, 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
2010-01-22 12:20:21
+2
A:
The class java.util.LinkedList
has addFirst/Last(), getFirst/last() and removeFirst/Last().
Jerome
2010-01-22 11:54:20
+5
A:
Any collection that implements Deque
should have it (ArrayDeque
, LinkedList
)
fn
2010-01-22 11:57:59
@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
2010-01-22 12:10:51