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 › Arrays.. Processing and beyond
Page Index Toggle Pages: 1
Arrays.. Processing and beyond (Read 440 times)
Arrays.. Processing and beyond
Mar 22nd, 2010, 10:05am
 

I was using Processing to do the design for an Andriod application that I am developing. I was trying to stick to using methods that would be universally available between both.

My question concerns the methods you can invoke on arrays in processing:
shorten()
cancat()
subset()
etc.......

Looking at the Java Docs from http://java.sun.com/j2se/1.5.0/docs/api/java/util/Arrays.html I didn't see any of these methods. Am I looking in the wrong place or are these Processing specific.

My second question is concerning ArrayLists is there such a thing as a 2D array list ArrayList [][]???? or should I just be pulling data from my 2d array into an ArrayList modifying it and dumping it back into my 2d array?
Re: Arrays.. Processing and beyond
Reply #1 - Mar 22nd, 2010, 1:13pm
 
Quote:
I didn't see any of these methods. Am I looking in the wrong place or are these Processing specific.


I am fairly confident that these are Processing specific...

Quote:
My second question is concerning ArrayLists is there such a thing as a 2D array list ArrayList [][]????


ArrayLists are Objects (Lightweight Components) that extend the functionality of Arrays and add more Java-style features (such as getter/setter methods, arbitrary, combined object types and better exceptions etc). In order to instantiate an ArrayList you must create a new one with the 'new' operator, just as you'd do with any other object:

ArrayList foo = new ArrayList();

In order to create a n-D ArrayList you must create an ArrayList that contains ArrayLists. For 2-D eg. you'd make an arrayList that contains ArrayLists which contain your objects. For higher dimensions, more levels of nesting are required. Or you can just build your own class that takes indices as parameters and does the dirty job for you.

In general arrayLists are more flexible, but that goes in expense of computational time for access, storage etc, since more things need to happen to access or modify a variable list with arbitrary components than a fixed-length fixed-type one.

To sum up: Use ArrayLists for flexibility and arrays for speed.

Or, as you said, you can use ArrayLists where you need to do heavy modifications and then switch back to arrays for speed.
Page Index Toggle Pages: 1