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

    Unhappy Creating an Iterator for Linked List

    Hi,
    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
    Thanks.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,900
    Rep Power
    25

    Default

    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
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    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
    Posts
    68
    Rep Power
    0

    Default

    +1 on last post....try out with arrays....store 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, 04:34 PM
  2. Linked List help
    By neobie in forum New To Java
    Replies: 8
    Last Post: 12-22-2007, 04:15 AM
  3. going from vectors to linked list?
    By cbrown08 in forum New To Java
    Replies: 3
    Last Post: 12-01-2007, 01:55 AM
  4. Linked List
    By rnavarro9 in forum New To Java
    Replies: 0
    Last Post: 11-29-2007, 04:42 AM
  5. Help with linked list
    By trill in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 08: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
  •