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.
Page Index Toggle Pages: 1
2D ArrayList (Read 1739 times)
2D ArrayList
Oct 26th, 2007, 6:56am
 
I've been at this one for a while now.
I've created an initial ArrayList and then I add more ArrayList in it (so it becomes a 2D array). No problem there.

example:
-----------------------------------------------------
ArrayList root = new ArrayList();

ArrayList subArray = new ArrayList();
subArray.add("text01");
subArray.add("text02");

root.add(subArray);
-----------------------------------------------------

So far, so good, No error.
The problem is, when I try to read the data.
-----------------------------------------------------
println(root.get(0)) //returns [text01, text02];
-----------------------------------------------------

Problem there, is I can't access the information after that because it returns an Object.

My question is, is there any way I could access the information in my Object or can I convert my Object to an Array?

Any help would be very appreciated.

Re: 2D ArrayList
Reply #1 - Oct 26th, 2007, 9:13am
 
You have to cast the object you get into an ArrayList :

Code:
ArrayList array = (ArrayList)root.get(0);
println(array.get(0));
println(array.get(1));
Re: 2D ArrayList
Reply #2 - Oct 26th, 2007, 5:21pm
 
I should have thought about the (ArrayList).
Thanks alot antiplastik!
Page Index Toggle Pages: 1