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 › JAVA Array Object
Page Index Toggle Pages: 1
JAVA Array Object (Read 1274 times)
JAVA Array Object
Mar 26th, 2007, 7:07pm
 
JAVA has an Array object that's more flexible then the usual static array (int[] myArray = new int[ 3]) but for the life of me I can't remember it...

It's more flexible then the regular array. I used it last year in processing and it worked... I tried to find it but can't.

if you know, please point me the way. thanks

m
ps. it's pretty sweet.. Processing should document it.
Re: JAVA Array Object
Reply #1 - Mar 26th, 2007, 8:39pm
 
ArrayList?
Re: JAVA Array Object
Reply #2 - Mar 26th, 2007, 8:41pm
 
YES!
thanks
Re: JAVA Array Object ( ArrayList )
Reply #3 - Mar 26th, 2007, 9:02pm
 
here's an example of it working
Code:

ArrayList myList = new ArrayList();

void setup()
{
 size(200, 200);
 myList.add("A");
 myList.add("B");
 print(myList.get(0) +":"+ myList.size() );
}



here's documentation on it
http://java.sun.com/j2se/1.4.2/docs/api/java/util/ArrayList.html

You don't have to specify the number of index, datatypes, and there's cool methods regular arrays don't offer like finding the length of the array.
Re: JAVA Array Object
Reply #4 - Mar 27th, 2007, 4:16am
 
mistergreen wrote on Mar 26th, 2007, 7:07pm:
ps. it's pretty sweet.. Processing should document it.

it's also slower than just using arrays, and requires that all data (even ints and floats) be wrapped as objects, which is significantly slower. it also makes you get into typing issues. we don't have much to add to the reference over the way it's described in sun's javadoc, so it's not something that we cover.
Re: JAVA Array Object
Reply #5 - Mar 27th, 2007, 5:29am
 
speaking of typing issues..
have you tried to append an object into an array?

like..
Code:

myClass [] myArray = new myClass[ 0];
myArray = append(myArray, new myClass() );

this will give me a typing error... Processing doesn't agree myArray & new myClass() as the same typing?  I tried casting it too and it doesn't work either.
like:
Code:

myClass [] myArray = new myClass[ 0];
myClass temp = new myClass();
myArray = append(myArray, (myClass) temp );


ArrayList will let me do it.. that's partly why I'm using it instead.
Re: JAVA Array Object
Reply #6 - Mar 27th, 2007, 9:58am
 
Code:

class myClass {
}

myClass[] arr = new myClass[12];

arr = (myClass[])append( arr, new myClass() );

println( arr.length );


F
Re: JAVA Array Object
Reply #7 - Mar 27th, 2007, 3:24pm
 
oh. interesting.
thanks.
Page Index Toggle Pages: 1