7

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

George
  • 8,368
  • 12
  • 65
  • 106

3 Answers3

11

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

Jerome
  • 8,427
  • 2
  • 32
  • 41
7

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

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
fn.
  • 2,788
  • 2
  • 27
  • 29
  • @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
  • 1
    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 Jan 22 '10 at 12:20