Home>
What's the difference between removeFirst () and pop () in Deque?
-
Answer # 1
-
Answer # 2
According to the documentation, the only difference is that removeFirst () throws an exception if the queue is empty
According to what documentation and what deck implementation?
DmitriyD2021-02-23 18:30:49According to the documentation orakl to the deque interface. In the question, the implementation is not specified, but the ones I used did it.
Folko852021-02-23 18:30:49I will upset you, and both methods will throw an exception.
DmitriyD2021-02-23 18:30:49 -
Answer # 3
Nothing. The
pop ()
method internally calls theremoveFirst ()
method and calling the first or second is equivalent.
It's simple. The methods are equivalent. But there is a recommendation. If
Deque
is used as a deque, thenremoveFirst ()
is preferred. IfDeque
is used as a LIFO stack (and it is suitable for this task), then it is preferable to usepop ()
.Similar methods:
push
(for stack) -addFirst
(for queue),peek
(for stack) -peekFirst
(for the queue).