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 › Retrieving values from a LinkedList
Page Index Toggle Pages: 1
Retrieving values from a LinkedList (Read 555 times)
Retrieving values from a LinkedList
Nov 28th, 2006, 1:57pm
 

Could someone please assist me by demonstrating how Processing can store values in a dynamic array. The following returns mismatched Object types.

LinkedList a = new LinkedList();
int[] b = {1, 2};
a.add(b);
b = a.get(0);
println(a.get(0)[0]);
Re: Retrieving values from a LinkedList
Reply #1 - Nov 28th, 2006, 2:24pm
 
When retrieving items from an object array (LinkedList) you need to cast them from the Object type (as they exist in the array) into the type you put into the array.

In your case an integer array (int[])
Code:

LinkedList a = new LinkedList();
a.add(new int [] {1, 2});
int [] temp = (int[])a.get(0);
println(temp);

Most folks these days are using ArrayList or Vector (Both linked lists with an added ability to control internal capacity for speed purposes, the difference with Vector is that it's synchronised between threads - uncommon in Processing applets).
Re: Retrieving values from a LinkedList
Reply #2 - Nov 28th, 2006, 2:32pm
 
Thanks very much, st33d Smiley
Page Index Toggle Pages: 1