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
How to splice? (Read 665 times)
How to splice?
Dec 11th, 2009, 11:13am
 
How do you append an Object to an array?
Re: How to splice?
Reply #1 - Dec 11th, 2009, 11:27am
 
Use the append() method.

Code:
Object[] items = (Object[]) append(yourArray, yourObject); 

Re: How to splice?
Reply #2 - Dec 11th, 2009, 11:33am
 
Wouldn't it expand the array? Can't I designate it to an specific index?
Re: How to splice?
Reply #3 - Dec 11th, 2009, 11:46am
 
Do you mean splice like array_splice in PHP

Did you have a look at the reference Maybe the splice() method would fit your needs

Otherwise, please give an example of expected result.
Re: How to splice?
Reply #4 - Dec 11th, 2009, 6:07pm
 
Guilherme wrote on Dec 11th, 2009, 11:33am:
Wouldn't it expand the array Can't I designate it to an specific index


Yes, by doing the following.

Code:
array[x] = Object; 



Where x is the space in the array you wish to insert the object. It starts counting from zero.

Splice and append will add elements to your array, so if there's an empty slot (null) at the end and you append an object, the slot will just get nudged.
Page Index Toggle Pages: 1