Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: ArrayList<node> list

  1. #1
    Member
    Join Date
    Apr 2014
    Posts
    223
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Question ArrayList<node> list

    import java.io.*;
    import java.util.ArrayList;
     
    public class SpiltList
    {
    	private class node
    	{
    		int number;
    		node next;
    	}
     
    	ArrayList<node> list = new ArrayList<node>();
    	void crap()
    	{
     
    	for(int i=0;i<90;i++)
    	{
    	node temp=new node();
    	temp.number = i;
    	temp.next = null;
     
    	list.add(temp);
    	}
     
    	while(!list.isEmpty())
    	{
    	System.out.println(list.node.number);
    	}
    	}
    	public static void main(String[] args) 
    	{
    		SpiltList s = new SpiltList();
     
    		s.crap();
    	}
     
    }

    I am using an ArrayList to make a list of nodes. I cannot seem to find documentation on how to call the nodes, just find how to get int and strings from a list.


  2. #2
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    711
    Thanks
    0
    Thanked 130 Times in 113 Posts

    Default Re: ArrayList<node> list

    The documentation of the List interface gives you various ways of accessing the contents of a list:
    List (Java Platform SE 7 )

    Pick any of these, for your use case the iterator would probably be best suited.
    But you may also use the get(int index) method.

  3. #3
    Member
    Join Date
    Apr 2014
    Posts
    223
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default Re: ArrayList<node> list

    	Iterator<node> it = list.iterator();
    	while(it.hasNext())
    	{
    	System.out.println(it.next().number);
    	}
    	}
    	public static void main(String[] args) 
    	{
    		SpiltList s = new SpiltList();
     
    		s.crap();
    	}

    Got it thanks

Similar Threads

  1. getting data from arraylist into a drop down list
    By nallamchaitanya in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 13th, 2013, 04:42 AM
  2. Arraylist of averages of two arrays list
    By Hazmat210 in forum Collections and Generics
    Replies: 11
    Last Post: April 5th, 2012, 07:38 PM
  3. Array List; How to pass objects into another arraylist
    By Melvrick in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 24th, 2011, 05:55 AM
  4. LIST NODE TROUBLES
    By YONATAN in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 26th, 2011, 03:35 AM
  5. Need help outputting sub-list of an ArrayList
    By Allusive in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 24th, 2010, 09:20 AM