• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Iterator vs. ListIterator

 
Ranch Hand
Posts: 246
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What exactly is the difference between interface {Iterator<E>} and its subinterface {ListIterator<E>}? I guess I'm asking what exactly does one get from {ListIterator<E>} that {Iterator<E>} doesn't have?

Kevin S
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kevin Simonson wrote:What exactly is the difference between interface {Iterator<E>} and its subinterface {ListIterator<E>}? I guess I'm asking what exactly does one get from {ListIterator<E>} that {Iterator<E>} doesn't have?



Have you looked at the JavaDoc for java.util.ListIterator? It is pretty easy to figure out.

Henry
 
Ranch Hand
Posts: 144
MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Information straight from API

Interface Iterator<E>: An iterator over a collection. It has three methods hasNext(), next() & remove()

public interface ListIterator<E>: An iterator for lists that allows the programmer to traverse the list in either direction , modify the list during iteration, and obtain the iterator's current position in the list. The methods are

add (E e), hasNext(), hasPrevious(), next(), nextIndex(), previous(), previousIndex(), remove(), set(E e).

For more information, please check the following API link.

So Major difference is with Iterator you can move only in one direction while ListIterator you can traverse in wither direction.

Hope this helps.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Zeeshan Sheikh wrote:
Hope this helps.



Not really, no. The OP was already directed to the API docs. Spoonfeeding it to him is not helpful.
 
Zeeshan Sheikh
Ranch Hand
Posts: 144
MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeff I will keep this in mind for next time.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Zeeshan Sheikh wrote:Jeff I will keep this in mind for next time.



Thanks!
 
Today's lesson is that you can't wear a jetpack AND a cape. I should have read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic