You're probably right.
The ArrayList or Vector may help, since they both have a toArray() method.
http://java.sun.com/j2se/1.4.2/docs/api/java/util/List.html
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Vector.html
http://www.javacoffeebreak.com/faq/faq0017.html
I'm a Processing/Java beginner so I'm not familiar with Collection, List, ...
but someday I will learn to use them.
I tried this code,
Code:void setup() {
size(120,120);
background(153);
noLoop();
}//setup()
void draw() {
// Create an instance of class Vector, with initial vector size
System.out.println("--- input to Vector ---");
Vector myVector = new Vector(10);
for (int i=1; i<=3; i++) {
myVector.addElement( new Integer(i));
System.out.println(i);
}
// Traverse list, printing them all out
System.out.println("--- output from Vector ---");
for (Enumeration e = myVector.elements(); e.hasMoreElements();) {
Integer num = (Integer) e.nextElement();
System.out.println(num);
}
// convert to an array
System.out.println("--- Vector to Array ---");
System.out.println("myVector.size() = "+myVector.size());
Integer[] myArray = new Integer[myVector.size()];
myVector.toArray(myArray);
// output array
System.out.println("--- output from array ---");
for (int i=0; i<myArray.length; i++) {
System.out.println(myArray[i]);
}
// Traverse list, printing them all out
System.out.println("--- output from Vector ---");
for (Enumeration e = myVector.elements(); e.hasMoreElements();) {
Integer num = (Integer) e.nextElement();
System.out.println(num);
}
}//draw()
It's working, but there are 2 problems for my needs:
-- converting the Vector to an array keeps the Vector, so my whole list is now duplicated in memory.
-- the array is an Integer array, it has to be duplicated again by copying it into an int array.
This doesn't work
Code:Integer aa=12;
int bb=(int) aa;
but this works
Code:// to int i from Integer ii
int i = ii.intValue();
// to Integer ii from int i
Integer ii = new Integer( i );
found at http://mindprod.com/jgloss/intvsinteger.html
The more I know, the more I think Java is badly designed from the start, making complex what used to be simple in Pascal or Basic.