Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

urgent please

 
anveshana bandu
Ranch Hand
Posts: 42
  • 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.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take the time to choose the correct forum for questions; this one is for exam results: CarefullyChooseOneForum

You should also UseAMeaningfulSubjectLine.

This particular question was, amazingly enough, asked by someone else just minutes before you did, so let's continue the discussion in that thread. Goes to show that you should really search through the archive of posts before asking a question: SearchFirst
[ November 22, 2007: Message edited by: Ulf Dittmer ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic