Size-limited queue that holds last N elements in Java

A very simple & quick question on Java libraries: is there a ready-made class that implements a Queue with a fixed maximum size – i.e. it always allows addition of elements, but it will silently remove head elements to accomodate space for newly added elements. Of course, it’s trivial to implement it manually: import java.util.LinkedList; … Read more

Queue.Queue vs. collections.deque

I need a queue which multiple threads can put stuff into, and multiple threads may read from. Python has at least two queue classes, Queue.Queue and collections.deque, with the former seemingly using the latter internally. Both claim to be thread-safe in the documentation. However, the Queue docs also state: collections.deque is an alternative implementation of … Read more

Cannot instantiate the type Queue. Why is this?

This is my main method for a stacks/queues assignment. I keep getting an error with my queue, but not my Stack. The stack class seems to be working just fine. I’m completely stuck. It says “cannot instantiate type Queue”. Any help would be most appreciated! public class mainMeth { public static void main(String[] args) throws … Read more

Enqueue, Dequeue and ViewQueue in Java

Java queues don’t have enqueue and dequeue methods, these operations are done using the following methods: Enqueuing: add(e): throws exception if it fails to insert the object offer(e): returns false if it fails to insert the object Dequeuing: remove(): throws exception if the queue is empty poll(): returns null if the queue is empty Take … Read more