Skip to content

Tag: queue

How do I instantiate a Queue object in java?

When I try: The compiler is giving me an error. Any help? Also, if I want to initialize a queue do I have to implement the methods of the queue? Answer A Queue is an interface, which means you cannot construct a Queue directly. The best option is to construct off a class that already implements the Queue inte…

Is there a fixed sized queue which removes excessive elements?

I need a queue with a fixed size. When I add an element and the queue is full, it should automatically remove the oldest element. Is there an existing implementation for this in Java? Answer There is no existing implementation in the Java Language and Runtime. All Queues extend AbstractQueue, and its doc clea…