Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

JavaWorld Daily Brew

Iterator's implementation

Tags:

Hi all,

Am a new user to Java world. I have a clarification on methods of Iterator interface. Iterator interface provides hasNext(), next() and remove() methods. From the Javadoc, class BeanContextSupport implements Iterator.

In collections like ArrayList, HashTable, HashSet, Vector we make use of those 3 methods to traverse through and remove objects. If you take ArrayList's hierarchy, I don't find BeanContextSupport in picture. In that case, which implementation does an ArrayList (or any collection) take for those 3 methods?

Thanks,
Maria

Your rating: None Average: 3.5 (2 votes)

Hi Maria, I think you should

Hi Maria,
I think you should look at source code of AbstractList's iterator() method for your answer.

Iterator's implementation

The Iterator that you get out of an ArrayList with ArrayList.iterator() is an instance of AbstractList$Itr, which is a private class inside AbstractList. All this has nothing to do with BeanContextSupport.

The javadoc says BeanContextSupport implements Iterable, not Iterator. It's inherited in the following way:
BeanContextSupport implements BeanContext which extends Collection which extends Iterable.

The Iterable interface allows classes to be run inside a foreach statement. (Java 1.5)

Re:

This is a private class inside AbstractList. All this has nothing to do with BeanContextSupport.
Online school | Bachelor degrees | Online degrees

Re:

The Iterable interface allows classes to be run inside a foreach statement.
online Doctorate degrees | Applied Arts School

Re:

The Iterable interface allows classes to be run inside a foreach statement.
Online University

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <p> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <br /> <br> <strike>
  • Lines and paragraphs break automatically.
  • Use <!--pagebreak--> to create page breaks.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
Just checking to see if you're an actual person rather than a spammer. Sorry for the inconvenience.