Results 1 to 4 of 4
  1. #1
    spanky is offline Member
    Join Date
    Oct 2008
    Rep Power

    Unhappy Creating an Iterator for Linked List

    I'm trying to make an iterator for a class I'm making and I need to define a next() and hasNext() method. I understand what each one does but I don't understand how to define those two methods without implementing Iterator. The whole point is to make our own.
    Anything would help

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power


    Iterator is an interface and you must implement it. That is the whole point of interfaces. They define what methods you MUST have in the class you write so that users of that class will know what methods can be used to get the job done. What goes in the methods is up to you.

  3. #3
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Rep Power


    As Norm states, but start with simple array in the class as a place to start. Work towards seeing how we traverse the array, leave sorting for later. That will build to you assignment. Putting elements in 1,2,3,4,5... arrangement is useless distraction until one can traverse the elements. Java Collections has numerous pre-built examples but try to figure do one yourself first.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  4. #4
    Join Date
    Oct 2008
    Rep Power


    +1 on last post....try out with it in instance level and maintain a location identifier so that u can move forward....

Similar Threads

  1. creating a deck of cards using a linked list
    By boomba88 in forum New To Java
    Replies: 2
    Last Post: 09-11-2008, 03:34 PM
  2. Linked List help
    By neobie in forum New To Java
    Replies: 8
    Last Post: 12-22-2007, 03:15 AM
  3. going from vectors to linked list?
    By cbrown08 in forum New To Java
    Replies: 3
    Last Post: 12-01-2007, 12:55 AM
  4. Linked List
    By rnavarro9 in forum New To Java
    Replies: 0
    Last Post: 11-29-2007, 03:42 AM
  5. Help with linked list
    By trill in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 07:29 AM

Posting Permissions

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