Results 1 to 2 of 2
  1. #1
    pyler is offline Member
    Join Date
    Jul 2012
    Posts
    18
    Rep Power
    0

    Default List only appends one item

    Node inside a linkedlist
    SomeInterface has an
    Java Code:
    addLast()
    method that should add a node at the end of the list
    Java Code:
    public sizeCount=0;
    public LinkedList<T> implements SomeInterface<T>{protected class Node<T>{
    		privateT data;
    		private Node<T> head,tail;
    		protected Node(T data,Node<T>tail){
    			this.data=data;head=null;this.tail=tail;}
    		private T getInfo(){return this.data;}
    		private void setTail(Node<T>newTail){this.tail=newTail;}
    		private void setLink(Node<T>newHead){this.head=newHead;}
    		private Node<T> getLink(){return tail;}
    		}}
    public void addLast(){
    
    }
    }//end of LinkedList<T> class
    when I create a LinkedList object (
    Java Code:
    LinkedList<String>somelist=new LinkedList<T>()
    ) and try to append multiple items (
    Java Code:
    somelist.append("William");somelist.append("Fredkrick");somelist.append("Maria")
    ) only the last item/string gets appended to the list. Any reason why?

    Also, here's the
    Java Code:
    append()
    method
    Java Code:
    Node<E>topNode=null;
    append(E thing){
    if(thing==null){throw new InvalidInputException();}
    else{
        if(topNode==null){
            topNode=new Node<E>(thing,null);
            sizeCount++;return this;}
        if(topNode.tail==null){topNode.tail=new Node<E>(thing,null);return this;}
        else{topNode=topNode.tail;append(thing);return this;}
            }
           }
    Last edited by pyler; 02-23-2014 at 11:58 PM.

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

    Default Re: List only appends one item

    Please edit your post and wrap your code with code tags:
    [code]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    Also the code needs to reformatted. There should only be one statement per line.
    There should not be code on the same line as a }
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. unselected item from selected list
    By prasathbala in forum NetBeans
    Replies: 0
    Last Post: 01-10-2012, 06:41 AM
  2. How to add item on list
    By Aenohe in forum New To Java
    Replies: 4
    Last Post: 12-09-2011, 12:05 AM
  3. access array list item from draw
    By trishtren in forum New To Java
    Replies: 8
    Last Post: 04-19-2011, 01:34 PM
  4. Appending and item to a Select List
    By Samurai Coder in forum New To Java
    Replies: 1
    Last Post: 12-04-2009, 11:56 PM
  5. Button to remove item from list
    By dacool25 in forum Java Applets
    Replies: 6
    Last Post: 10-14-2009, 05:30 AM

Tags for this Thread

Posting Permissions

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