Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Difference between Queue implementations

Hello Guys,

I would like to use collections to store, retrive my data. My friends suggested to get acquainted with the Queue data structure.

Queue has general-purpose implementations like PriorityQueue, and concurrent implementations (LinkedBlockingQueue, DelayQueue).

But I can't decide which data structure is more suitable than others.
Could someone please give me an explaination of these implementation?
e.g. What is the difference between PriorityQueue and concurrent queues?

Any help would be most welcome!

Thanks.


First step, I start with the DelayQueue and try to add String element to it.
[code]
import java.util.concurrent.DelayQueue;
import java.util.Queue;
public class Collect{
public static void main(String[] args)
{
Queue qu = new DelayQueue();
qu.add("apple");
}}
[/code]

But I received the following exception at runtime:

[italic]Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot
be cast to java.util.concurrent.Delayed
at java.util.concurrent.DelayQueue.add(Unknown Source)
at Collect.main(Collect.java:7)[/italic]



Sign In or Register to comment.