Is there any collection class in java, that implements push_back()
and push_front()
methods?
Asked
Active
Viewed 1.9k times
7

George
- 8,368
- 12
- 65
- 106
3 Answers
11
The class java.util.LinkedList
has addFirst/Last(), getFirst/last() and removeFirst/Last().

Jerome
- 8,427
- 2
- 32
- 41
-
push_back() = addLast(), push_front() = addFirst(). – Cipi Jan 22 '10 at 11:59
7
Any collection that implements Deque
should have it (ArrayDeque
, LinkedList
)
-
@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 Jan 22 '10 at 12:10
1
The List
appears to with both add
functions.
https://docs.oracle.com/javase/1.5.0/docs/api/java/util/List.html

fospathi
- 537
- 1
- 6
- 7

Daniel A. White
- 187,200
- 47
- 362
- 445
-
1Hmm, 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 Jan 22 '10 at 12:20