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
  • 263,859
  • 56
  • 671
  • 702
Zip
  • 4,524
  • 8
  • 26
  • 38

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,147
  • 4
  • 22
  • 40