Abimaran Kugathasan wrote:For these question, as Ankit said, search it.
System.out.println is invoking the toString() method of the PriorityQueue, which is using the iterator, which is not guaranteed to respect the natural ordering. From the docs: "The Iterator provided in method iterator() is not guaranteed to traverse the elements of the priority queue in any particular order."So when you print the PriorityQueue with System.out.println(), you won't get order(natural/yours). If you print them manually as Sandra did, you'll get the order!
Sandra Bachan wrote:Based on the discussions on this forum, seems that you have to manually poll() or peek() to have queue printed in order, such as the code below (as)
Output:
1 2 3 4 5 6
This output is perfect only when numbers of Integer class or String class ex- "1" ,"8", "4","2" is considered & the putput wud still be orderd removal by poll()
But when PriorityQueue<String> pq ---->"Seventy", "Six ","One", " Two", like this unordered strings are loaded poll wud worka as deisred. I mean the output of using above code would not produce the ordered removal by pq.poll().
hence the question posed by Sandra Bachan is unanawered. As he/she wanted 2 then 4 to removed.
kindly forgive me if I'm wrong, but I too had the same question wherein I feel Priority Queue would not work for String of chars.
Jim Hoglund wrote:So what happens when you run "java CommandLineTest one two" ?
java CommandLineTest one two" -> this is not what i run.
c:\java\javac Commandline is what I run One two i the output
Jim Hoglund wrote:Isn't CommandLineTest the name of your class?
Jim ... ...
Srinivas Katta wrote:Hi All,
I have Cleared SCJP 6 Exam, I am very happy to see the result, Thanks to all for your Help. Thanks to Java Ranch for hosting these kind of Forums
Thanks
Srinivas
Another Interesting point is an Interface can be declared with strictfp but no interface can have strictfp declared method.phil sohar wrote:from kathy ............
page no 46........
it can modify a class or method declaration, and that a variable can never be declared strictfp............
but in examlab.........the answer say..........strictfp can be used for instance variable and class.....
which one is correct
Bert Bates wrote:I totally agree with "code, code, code"...
One idea is that every mock exam question you look at (whether it's from K&B or some other source), has the potential to be a small program that you can recreate and study, and modify, and test, and in general futz around with. So find a question you have some doubts about, type it in, compile it, run it, tweak it, compile and run again.
hth,
Bert
Ankur kothari wrote:by the way i dont think there will be questions on countries asked in the exam