We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › getting data from an arraylist
Page Index Toggle Pages: 1
getting data from an arraylist (Read 558 times)
getting data from an arraylist
Feb 8th, 2010, 7:13pm
 
Hi, this is clearly a syntax question. guess its easy to answer.
Ive created an arraylist of objects holding some data in different variables.

when using an array I usually do it that way to print out the stored x,y coordinates.

for(int i = 0; i<object.length();i++){
println(object[i].x);
println(object[i].y);
}

how would that look like when using an arraylist ?
Re: getting data from an arraylist
Reply #1 - Feb 8th, 2010, 10:40pm
 
Code:
Coordinate xy; //some class that contains an x and y value

ArrayList al = new ArrayList();

//Add things to the list...

for(int i=0; i<al.size(); i++){
 xy = (Coordinate)al.get(i); //Cast the returned Object to something we know

 println(xy.x + "-" + xy.y);
}

Or for a working example:
http://processing.org/reference/ArrayList.html
Re: getting data from an arraylist
Reply #2 - Feb 9th, 2010, 4:33am
 
alright, i know why it was not working. i used the same name for the arraylist inside the class i am storing the objects in as for the objects itself Smiley
Page Index Toggle Pages: 1