This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regarding scjp 1.5

 
anveshana bandu
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PriorityQueue<String> que=new PriorityQueue<String>();

que.add("silpa");
que.add("swati");
que.add("roopa");
System.out.println(que);
System.out.println(que.poll());
System.out.println(que.peek());

output:::[roopa, swati, silpa]
roopa
silpa

mydoubt:::why did the elements in the list are not in sorted order??i feel silpa and swati should be interchanged.so that they will be in sorted order.
i understood the functionality of poll() and peek()..my doubt is in what order the elements are printed in case of strings if we print the whole collection that is queue.
 
Kelvin Chenhao Lim
Ranch Hand
Posts: 513
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
Please don't cross-post the same question to multiple forums.
Your question has been answered in the SCJP forum.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic