Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a material difference between pop() and remove() in Java ArrayDeque?

Both remove and pop remove and return an element from the front of the Queue. They both throw an exception if there's an empty Queue.

like image 985
swarbrick85 Avatar asked Apr 02 '26 18:04

swarbrick85


1 Answers

There is no difference. In fact, pop() and remove() methods both call removeFirst. See https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/util/ArrayDeque.java

public E remove() {
    return removeFirst();
}

public E pop() {
    return removeFirst();
}
like image 138
Joni Avatar answered Apr 04 '26 07:04

Joni