TCLUG Development Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [TCLUG-DEVEL:208] Queue in JDK 1.2?



I would advise against using Vector as a queue.

Vector is backed by a packed array, meaning that adding and removing at
the end is fast and efficient, but adding or removing at the beginning
(or middle) is O(n).  

As long as your queue stays small it's not that big a deal, but I would
suggest a java.util.LinkedList.  

If you need synchronization (LinkedList is not threadsafe by nature),
then you can create it via the java.util.Collections class.

List myQueue = Collections.synchronizedList(new LinkedList());

--- Jon Schewe <jpschewe@eggplant.mtu.net> wrote:
> 
> You can treat the Vector class as a queue, the Stack class is just a
> subclass
> of Vector anyway.
> 


__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com