Results 1 to 3 of 3
  1. #1
    Slobdell is offline Member
    Join Date
    Jul 2011
    Posts
    2
    Rep Power
    0

    Default Editing objects within a LinkedList?

    Hi this is probably a dumb questions but it's my first time using LinkedLists. Should be simple.

    I have a LinkedList of objects. I want know how to access the object methods within a specific LinkedList node.

    For example, in an array I would use the following code:

    Array[slot location].ObjectMethod().

    I can't figure out how to do this to, say, use the add() method to the object in say the 4th node.

    LinkedList[3].ObjectAddMethod()?

    This is confusing, here is my broken code if you need a better idea of what I'm talking about.



    Java Code:
    public static void loadData(Scanner infile, LinkedList libsys){
            int type, onshelf, lost, volume, status, ctr = 0;
            String title, author, itemid, line;
            
            while (infile.hasNext()){
                type = infile.nextInt();
                itemid = infile.next();
                infile.nextLine();
                title = infile.nextLine();
                if (type == 1){
                    libsys.add(new Book(itemid, title));
                    line = infile.nextLine();
                    StringTokenizer tkn = new StringTokenizer(line," ");
                    while (tkn.hasMoreTokens()){
                        author = (String)tkn.nextToken();
                        // Then I want to add this author to the LinkedList
                        // within the Book object I created above...which is located
                        // in the first node of the LinkedList libsys
                    }
                } 
            // This counter was my reference to with node within the LinkedList
            // I'm refering to
            ctr++;
            }
        }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default

    how to access the object methods within a specific LinkedList node
    Use one of the linked lists methods to get the object reference from the list.
    With that object reference you can call its methods.
    Something like this, check API doc for the name of method(s) and its arguments:
    anObject = ll.get(33); // get object at loc 33
    anObject.aMethod(); // call the object's method

  3. #3
    Slobdell is offline Member
    Join Date
    Jul 2011
    Posts
    2
    Rep Power
    0

    Default

    Thank you that's exactly what I needed! Sometimes my brain turns to mush trying to take this all in as a newbie that the simple solutions get overlooked.

Similar Threads

  1. sound editing
    By nikkka in forum Advanced Java
    Replies: 3
    Last Post: 04-14-2011, 02:34 PM
  2. Problem with editing jar
    By DanielR in forum New To Java
    Replies: 16
    Last Post: 02-11-2011, 02:15 AM
  3. Photo Editing
    By stekun in forum Advanced Java
    Replies: 3
    Last Post: 02-23-2010, 05:11 AM
  4. Text editing
    By right2001 in forum New To Java
    Replies: 1
    Last Post: 04-10-2009, 07:03 AM
  5. Replies: 1
    Last Post: 01-22-2009, 04:25 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
  •