Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

In which class the Interface Iterator is implemented for Vector class

 
Arun raghvan
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In which class the Interface Iterator is implemented for Vector class
the code is shown below: where i don't implement the interface Iterator where it is defined.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I really don't understand your question. The Vector class implements the Iterable interface. Is that what you mean?
 
Arun raghvan
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouter Oet wrote: The Vector class implements the Iterable interface. Is that what you mean?


Yes ,Vector class must have implemented Iterator interface ...right ,why should it must implement Iterable...I can't understand the hierarchy is bit confusing. And On the following code i used iterator() Method where it is defined



sorry,my question was bit confusing.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The iterator method is defined in the Iterable interface and the vector implements that interface. If you're confused with the hierarchy just look at the java.util.Vector
 
Rob Spoor
Sheriff
Pie
Posts: 20531
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many Collection classes have a private inner class that implements Iterator. An instance of this class is returned. But you don't need to know what the actual class is. All you need to know is that it implements Iterator, and therefore has working hasNext() and next() methods, and possibly also a working remove() method (I said possibly since it's allowed to throw a UnsupportedOperationException from it).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic