Results 1 to 3 of 3
  1. #1
    bobbythecount is offline Member
    Join Date
    Aug 2013
    Posts
    4
    Rep Power
    0

    Default Linked Lists (again)

    Heyho people,


    i'm pretty sry, but how do i correctly use the subMethod "get".
    if i have the index of the Element i want to read as an int, how do i get the method get to work, as to read the Element at the specified index and then to write it into an varibale of the type element, so i can read that one out with getName.

    thx in advance

    bobbythecoutn

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

    Default Re: Linked Lists (again)

    Lets clarify:

    If you have a List containing:"apple", "banana", "cherry", "fig", "plum". Are you asking how to get the third String (cherry)? Presumably you have a variable pointing to the head of the List, then assign a temp variable to the same object. Use a loop to iterate through the List using object.next() or whatever method you have and do that index number of times. When you have finished return whatever object the temp variable is referencing.

    No I will not supply sample code. You attempt it and post your code here.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,773
    Blog Entries
    7
    Rep Power
    21

    Default Re: Linked Lists (again)

    Quote Originally Posted by bobbythecount View Post
    i'm pretty sry, but how do i correctly use the subMethod "get".
    if i have the index of the Element i want to read as an int, how do i get the method get to work, as to read the Element at the specified index and then to write it into an varibale of the type element, so i can read that one out with getName.
    Are you talking about your own linked list implementation or the one in the core classes of your Java distribution? (the one that implements the List interface).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Linked Lists
    By bobbythecount in forum New To Java
    Replies: 4
    Last Post: 08-20-2013, 02:30 PM
  2. help with linked lists
    By akusa in forum New To Java
    Replies: 1
    Last Post: 04-15-2013, 05:34 AM
  3. Linked Lists
    By ashplusham in forum New To Java
    Replies: 3
    Last Post: 11-20-2012, 09:05 PM
  4. Linked Lists
    By Dee in forum New To Java
    Replies: 18
    Last Post: 02-02-2011, 04:14 AM
  5. Linked Lists
    By vendetta in forum New To Java
    Replies: 6
    Last Post: 01-26-2010, 09:23 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
  •