This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes queue or priority oueue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "queue or priority oueue" Watch "queue or priority oueue" New topic
Author

queue or priority oueue

sam liya
Ranch Hand

Joined: Nov 25, 2008
Posts: 1240
what are the different between queue and priority oueue ?
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3886
    
    5

what are the different between queue and priority oueue ?


Queue is an interface whereas PriorityQueue is one of the implementations and there are few more.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
sam liya
Ranch Hand

Joined: Nov 25, 2008
Posts: 1240
no i am asking in general datas structure.
V K Gupta
Ranch Hand

Joined: Aug 07, 2008
Posts: 56
Hi,

Queue is an Interface present in java.util.Queue. Queue supports all Collections methods and other methods like
peek() : returns the highest priority queue and do not removes from the queue.
poll() : returns the highest priority queue and removes from the queue
offer(): add elements to the Priority Queue

These 3 methods are present only in Queue Interface. LinkList class also implements Queue Interface.

PriorityQueue : Is added in Java 5, PriorityQueue (PQ) is different from normal queue (FIFO) as PQ maintains the list as Priority IN and Priority OUT, the elements are ordered either in natural ordering or using comparator.


Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3886
    
    5

aruna sameera wrote:no i am asking in general datas structure.


Queues typically order elements in a FIFO (First-In-First-Out) and PriorityQueue orders the element using the provided comparator or the natural ordering of the elements. Check those links I gave above.
sam liya
Ranch Hand

Joined: Nov 25, 2008
Posts: 1240
how to implement a stack using two queues ?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 43368
    
  32
aruna sameera wrote:how to implement a stack using two queues ?
It would have been better to start a new thread, since that is a new subject.

And we don't simply give out such answers: you would do well to search and find a tutorial about the data structures for stacks and queues. Then tell us what you have learned and concluded, and we'll see what we think of it
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: queue or priority oueue
 
It's not a secret anymore!