Results 1 to 4 of 4

Thread: iterator

  1. #1
    TopNFalvors is offline Member
    Join Date
    Mar 2011
    Posts
    41
    Rep Power
    0

    Default iterator

    I have what is probably a silly question.

    What is an iterator and how does it work in a doubly-linked list?

    Is it is like a while loop like looping through an array?

    Thanks!

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,789
    Rep Power
    7

    Default

    An Iterator is simply a way to access each item is a collection one at a time and in order. It itself is not a loop but you use it in conjuction with a loop, either in the for each loop or while loop (while iterator has another item).

  3. #3
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

  4. #4
    TopNFalvors is offline Member
    Join Date
    Mar 2011
    Posts
    41
    Rep Power
    0

    Default

    Oh ok, I see, I found this example...

    Java Code:
     private static void useWhileLoop( Collection<String> aFlavours ) {
        Iterator<String> flavoursIter = aFlavours.iterator();
        while ( flavoursIter.hasNext() ){
          System.out.println( flavoursIter.next() );
        }
      }
    Thanks!

Similar Threads

  1. Iterator
    By Dayanand in forum New To Java
    Replies: 2
    Last Post: 03-10-2011, 12:17 PM
  2. for..iterator
    By jon80 in forum New To Java
    Replies: 2
    Last Post: 11-28-2010, 02:12 PM
  3. Replies: 0
    Last Post: 05-18-2010, 12:53 AM
  4. Iterator help
    By alpdog14 in forum New To Java
    Replies: 2
    Last Post: 10-13-2009, 08:42 PM
  5. Iterator
    By eva in forum New To Java
    Replies: 0
    Last Post: 01-31-2008, 02:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •