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 › ArrayList of integers; Java version
Page Index Toggle Pages: 1
ArrayList of integers; Java version (Read 5660 times)
ArrayList of integers; Java version
Aug 20th, 2007, 5:22am
 
My main issue is that I want to have a mutable array of integers. I've tried using an ArrayList, but I can't simply create one and add an int. So I tried using the Integer class. With Processing's version of Java, I can't do "ArrayList<Integer> array = new ArrayList<Integer>();". So I just tried array.add(new Integer(value));. That worked, but I want to be able to do addition with the Integers, and when I try to add a number to the Integer, I get several errors. I then tried making a new Integer by adding an int to the intValue() method of an Integer. That gave the error 'No accessible method with signature "intValue()" was found in type "java.lang.Object".'. What should I do? Is there a way around this without a custom class?

My second question is about the version of Java that Processing uses. I'm on Mac OS X, and I just installed Java SE 6. This does not seem to affect Processing (ArrayList<Integer> should work in Java 6), so I'm wondering what version of Java is used by Processing, and is there a way to use the latest? Thanks!
Re: ArrayList of integers; Java version
Reply #1 - Aug 20th, 2007, 11:19am
 
Processing uses Java 1.4. From what I've heard, even if you change processing's version of Java to 1.6 you still won't be able to use <Integer> type things, as the processing pre-processor will do strange things.
Re: ArrayList of integers; Java version
Reply #2 - Aug 20th, 2007, 11:22am
 
here's a bug for that (you can track there if it's fixed):

http://dev.processing.org/bugs/show_bug.cgi?id=598
Re: ArrayList of integers; Java version
Reply #3 - Aug 20th, 2007, 8:16pm
 
Quote:
Processing uses Java 1.4. From what I've heard, even if you change processing's version of Java to 1.6 you still won't be able to use <Integer> type things, as the processing pre-processor will do strange things.


Okay... I probably won't change the version, then, but how do you change it, just out of curiosity?

And so, if I can't do ArrayList<Integer>, what would be my best option for a mutable array of integers?
Re: ArrayList of integers; Java version
Reply #4 - Aug 20th, 2007, 11:50pm
 
To change the version of Java uses, rename the "java" direcdtory in the processing folder to something else, get the version you want and put that folder into your processing directory, and rename it "java"

As for a mutable array, you can use ArrayList, you just have to cast to int when you want to do anything with them.

It should be noted that doing this a lot can be a performance hit, since an int gets autoboxed into an Integer when put into the ArrayList, and then you have to cast it back (and it gets autounboxed) when you get it out.
Re: ArrayList of integers; Java version
Reply #5 - Aug 20th, 2007, 11:53pm
 
Would it be a better idea to do an ArrayList of custom objects that each have an int variable?
Re: ArrayList of integers; Java version
Reply #6 - Aug 20th, 2007, 11:57pm
 
IT depends entirely on what you're doing.

If the only bunch of variable you have are all ints, then it might actually be better to use a plain old int[] bigger than you'll ever need, with a couple of accessor methods that keep track of where the "end" is, and handle removing values.

If the ints are part of other objects, store the whole object.
Re: ArrayList of integers; Java version
Reply #7 - Aug 21st, 2007, 5:07am
 
just use an int array. to resize it use the expand() method as necessary:

Code:
int[] nums = new int[10];
int count;

void draw() {
for (int i = 0; i < count; i++) {
// do something with nums[i]
}
}

void add(int what) {
if (count == nums.length) {
nums = expand(nums);
}
nums[count++] = what;
}


i'd like to support 1.5 sometime soon, though updating the preprocessor is a bunch of work and i've had no volunteers.

support for 1.6 isn't a priority at all.. about 40-50% of processing users are on macs, and it appears as though Java 1.6 will require OS X 10.5. a number of our mac users are still stuck on OS X 10.3, which only goes to Java 1.4. complaints can be directed to apple: http://bugreport.apple.com

more ranting about versions/platforms is in the reference:
http://processing.org/reference/environment/platforms.html#java
Re: ArrayList of integers; Java version
Reply #8 - Aug 21st, 2007, 5:12am
 
I don't think 1.6 requires 10.5, because I was able to get the developer version on 10.4 with an ADC free membership (although it was considerably slower). Can't you just have Processing use the latest version of Java the user has?
Re: ArrayList of integers; Java version
Reply #9 - Aug 21st, 2007, 1:46pm
 
only the prerelease (note the date of that release) works on 10.4, all subsequent updates to 1.6 have been made for 10.5 only (and are only available to ppl who pay $500 or $1000 for the privilege of being in the apple dev program).

generally speaking it does use the most recent release installed. the bug report i listed above covers why that doesn't matter for syntax.
Page Index Toggle Pages: 1