wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Help with an Iterator question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with an Iterator question" Watch "Help with an Iterator question" New topic
Author

Help with an Iterator question

Vineeth Menon
Ranch Hand

Joined: Aug 08, 2011
Posts: 67

I have been learning Java for 5-6 months, my friend passed me this question regarding iterator for the first time in my life I have no clue what this means, can someone help me?



[Fixed code tags and formatting - see UseCodeTags for details]



VM
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1509
    
    5

Hello Jim Fields,

Welcome to CodeRanch!

Please, UseCodeTags. I can see a closing code tag, however, since, there is no opening code tag, the code snippet is quite difficult to read.

Also, please TellTheDetails. What exact part you are having trouble with? And what way of thinking you are following as of now?

I hope this helps.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
S.R Paul
Ranch Hand

Joined: Mar 22, 2012
Posts: 30

Hi Jim, The code itself doesn't make sense, since mostly no usable body in it.
What it is actually tying to do is, create a customized Iterator class, but lack of body code, nothing more.
All the collection interfaces implements Iterator, and tats just enough for normal use.

Next time try to post your code bit formatted


=-- Anything less than immortality is a complete waste of time --=
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4397
    
    8

Hi Jim. Welcome to the Ranch!

OK, what you've got there is a skeleton implementation of a custom Iterator. It looks like it's intended to wrap an existing iterator and add some additional functionality. Although as far as I can tell at first glance the additional functionality is just to optionally eliminate duplicates.

So the first question is, do you know what an Iterator is? If not, you need to read about those. If you do, you need to work out how to implement this one - you need to delegate to the wrapped Iterator, but then add whatever additional logic you need. What I'd suggest is as a first step get it delegating completely, so your Iterator works exactly the same as the one passed in. Then worry about the duplicates once you've got that working.

(A quick observation: getting a rough solution looks relatively straightforward. Getting a perfect one not so simple - I can see one tricky point).
Vineeth Menon
Ranch Hand

Joined: Aug 08, 2011
Posts: 67

Thanks a lot for the input guys, I guess I need to find out a way to implement the iterator functionality in this skelital implementation of this iterator...is that it???
Sammy Wilson
Greenhorn

Joined: May 28, 2012
Posts: 1
Here is my solution:

[Moderator action: Solution removed. This site is NotACodeMill.(⇐click)]
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Vineeth Menon wrote:Thanks a lot for the input guys, I guess I need to find out a way to implement the iterator functionality in this skelital implementation of this iterator...is that it???


Well, since we have:


I would say, yes, you need to do exactly that, as it appears to be the whole point of the exercise.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39076
    
  23
Sammy Wilson, welcome to the Ranch

Please note what it says on the contents page for this forum:
We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
That is why Jeff removed your post: it does not help people to be given too complete a solution too quickly.
 
GeeCON Prague 2014
 
subject: Help with an Iterator question