Saving the first element of an array into a new array

edited October 2016 in How To...

I am new to processing, I need to move the first element of an array into another array which stores all values of the first element from the first array

Please provide me with some coding or tips on how to approach this issue. Thank you.

Tagged:

Answers

  • edited October 2016

    If your intention is to append 1 element to some array, you can use append() for it:
    https://Processing.org/reference/append_.html

    However, arrays aren't supposed to change their length at all.
    For dynamic-sized arrays, go w/ ArrayList instead:
    https://Processing.org/reference/ArrayList.html

  • The first element of the array is not constant it will change,thus i want to store all the new values in a new array, is it possible to do so?

  • Like @GoToLoop said, you should be using ArrayList for that.
    Say you have an array "A" whose first element value keeps changing. Also create an ArrayList B.
    Now, each time before you change the value of first element of array "A", just call B.add(A[0]);
    Do that, and ArrayList B stores all the values you need.
    P.S. Technically you could use an array for it, but that would be far more inefficient.

Sign In or Register to comment.