Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Forums
Register
Login
Certification
»
Programmer Certification (OCPJP)
Thread - TreeSet Iterator
Sangita Mishra
,
Greenhorn
Jun 26, 2005 16:44:00
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
import java.util.*; import java.util.TreeSet; public class Thirsk{ public static void main(String argv[]){ Thirsk t = new Thirsk(); t.a19(); } public void a19(){ TreeSet tm = new TreeSet(); tm.add("Bill"); tm.add("Kathy"); tm.add("Carl"); Iterator it = tm.iterator(); while(it.hasNext()){ System.out.print(tm.next()+ " "); } } }[
It's giving compile error. Can somebody please tell me what would be the exact metoh of TreeSet iterator in this case?
[ June 26, 2005: Message edited by: Sangita Mishra ]
Abdulla Mamuwala
,
Ranch Hand
Jun 26, 2005 17:49:00
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
The TreeSet class does not have a method 'next', you need to call the method 'next' on the Iterator object. Check the API at,
TreeSet API
You need to make the following change for our code to compile, and show meangingful results,
while (it.hasNext()) { System.out.print(it.next() + " "); }
Post by:
autobot
brevity is the soul of wit - shakepeare. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
This thread has been viewed 766 times.
Similar Threads
Another question from mock exam
Collections
Marcus Green's Mock Exam 1 Question.
Will Collection class methods come in SCJP1.4 exam?
what's the error?
More...
All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 02:26:46
.