Results 1 to 6 of 6
Thread: Implement an Iterator
- 03-13-2011, 11:34 PM #1
- 03-13-2011, 11:42 PM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
What are you having trouble with? What have you tried?
- 03-13-2011, 11:50 PM #3
i dont understand what it is asking for exactly. I know what an iterator is, but not sure how I could implement one.
So, if I had a list L, that I wanted to iterate over
Then at this point, I would use i to represent the number of elements in my list?? I'm supposed to use some pseudo code.Java Code:int i=0; List L = new List(); L.add("1"); L.add("2"); Iterator itr = L.iterator(); while(itr.hasNext()){ Object nextItem = itr.next(); **Do Processing Here on the listItem** i++; }Last edited by sehudson; 03-13-2011 at 11:52 PM.
- 03-13-2011, 11:53 PM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
that looks pretty good, try putting a print statement after the loop to print the final value of i to see if it counted the items in the list.
- 03-14-2011, 12:01 AM #5
I cant implement a List since its abstract(forgot) so I set:
List L = new LinkedList();
put in the println and it indeed works.
- 03-14-2011, 12:02 AM #6
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Similar Threads
-
Iterator
By Dayanand in forum New To JavaReplies: 2Last Post: 03-10-2011, 12:17 PM -
for..iterator
By jon80 in forum New To JavaReplies: 2Last Post: 11-28-2010, 02:12 PM -
Iterator as return and argument or Iterator-String(not visible in the test file)
By Aldarius in forum New To JavaReplies: 0Last Post: 05-18-2010, 12:53 AM -
Iterator help
By alpdog14 in forum New To JavaReplies: 2Last Post: 10-13-2009, 08:42 PM -
Iterator
By eva in forum New To JavaReplies: 0Last Post: 01-31-2008, 02:07 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks