Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about PriorityQueue

 
Fred Victa
Ranch Hand
Posts: 185
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the following code supposed to place all of the integers in numerical order? If not, can anyone explain why?

public class myClass{


public static void main(String[] args)
{

PriorityQueue<Integer> x = new PriorityQueue<Integer>();
x.add(2);
x.add(66);
x.add(23);
x.add(1);
x.add(3);
System.out.println(x);
}

}
 
Stephan van Hulst
Bartender
Pie
Posts: 6113
72
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what does the program output? Does it match you expectations? Did you read the class documentation?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic