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 › Retrieve Array from an ArrayList
Page Index Toggle Pages: 1
Retrieve Array from an ArrayList (Read 886 times)
Retrieve Array from an ArrayList
May 19th, 2010, 3:27am
 
I've stored Arrays in an ArrayList by doing so:
Code:

a = split(rDataLines[i], ";");

dataList.add(a);


When I try to retrieve the first array from the ArrayList by using the following code, processing breaks and throws an ClassCastException.

Code:

ArrayList b = (ArrayList)dataList.get(0);
println(b.get(0));
println(b.get(10));


Any idea how to retrieve the first object (array) from the ArrayList as an 'usable' array instead of the default Object?
Re: Retrieve Array from an ArrayList
Reply #1 - May 19th, 2010, 4:46am
 
You store an array, you must get it back as an array:
String[] b = (String[]) dataList.get(0);
Re: Retrieve Array from an ArrayList
Reply #2 - May 19th, 2010, 4:52am
 
Thanks, that seems to make sense, except that it throws different error.

Cannot invoke get(int) on the array type String[]\n' ''
Re: Retrieve Array from an ArrayList
Reply #3 - May 19th, 2010, 5:53am
 
You have an array, use it like an array:
println(b[0]);
println(b[10]);
Re: Retrieve Array from an ArrayList
Reply #4 - May 19th, 2010, 6:05am
 
Embarrassed d'oh
Page Index Toggle Pages: 1