Skip to content
Advertisement

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.

Advertisement

Answer

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();
}
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement