Problems with toArray
in
Programming Questions
•
2 years ago
Hello all,
I'm using toArray to move data from a TreeSet to an array for ease of access in building an interface. When I use toArray in the function which uses the array theres no bother, i.e.
I'm new to processing beyond the basics, but I'm intregued as to why this happens? I had a look at the docs for toArray and saw this:
Thanks in advance.
I'm using toArray to move data from a TreeSet to an array for ease of access in building an interface. When I use toArray in the function which uses the array theres no bother, i.e.
- void someFunction(){
- Float myArray[] = new Float[mySet.size()];
- myArray = (Float[]) mySet.toArray(myArray);
-
- // Can access individual elements of the array easily.
- println(myArray[3]);
- }
- void setup() {
- Float myArray[] = new Float[mySet.size()];
- myArray = (Float[]) mySet.toArray(myArray);
- }
-
- void someFunction() {
- // This will throw an error, couldn't find anything named myArray
- println(myArray[3]);
- }
I'm new to processing beyond the basics, but I'm intregued as to why this happens? I had a look at the docs for toArray and saw this:
And wondered if this is related to my problem?The returned array will be "safe" in that no references to it are maintained by this collection
Thanks in advance.
1