Win a copy of Kubernetes in Action this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

regarding scjp 1.5  RSS feed

 
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.
 
Ranch Hand
Posts: 513
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!