Array expand doesn't always work?

Java arrays can’t have its length changed once created. :coffee:

What expand() and other similar functions do is create another array w/ a diff. length, copy the contents of the original array to the new 1, and then return the new 1. :face_with_monocle:

So we do need to store the newly returned array to some variable. :flushed:

That’s why an ArrayList, or in your particular case a StringList, is a much better choice as a dynamic length container: :bulb:

  1. Processing.org/reference/ArrayList.html
  2. Processing.org/reference/StringList.html
  3. Forum.Processing.org/two/discussion/8080/why-use-arraylist-instead-of-array-with-append
1 Like