1

Will a class become an iterator object itself if it implements an iterator interface.

For example,

public class StringGridIterator implements Iterator<String>{


    //some methods here...


}

or Do I need to specifically create a variable reference to an iterator object that will iterate through a certain String objects?

like this...

Iterator<String> it = object.iterator();

I don't know if this is clear enough for you to understand since I am still struggling with understanding Java concept like class and object myself.. Just leave a comment if you don't understand what I am trying to say.

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
Zip
  • 5,372
  • 9
  • 28
  • 39

1 Answers1

0

A class will not become an Iterator object by implementation. You may be thinking of extending a class. (See: What's the difference between the implements & extends keywords in Java).

From your examples, it looks like you are attempting to do 2 different things: class inheritance vs. an iterator object. The .iterator() method returns an Iterator containing the elements of your object.

Community
  • 1
  • 1
Chandrew
  • 16,987
  • 4
  • 24
  • 40