Array Lists

Flexible Arrays

Last week we were introduced to arrays. Or…I was introduced to arrays.

..I?

…We?

We don’t know. In any case the idea of an array was introduced to some conscious being/s. One of whom may or may not have been me. Or You.

One characteristic of these lists of items called arrays is that they have a fixed length. If you initialize an array with 8 slots (indexed 0 – 7), then it will always have 8 slots. If you want to change the length, you find where you initialized the array and change the length. Then you have to change that number everywhere you’re calling the array. Which is time consuming and kind of a pain in the ass. The solution is to use the syntax arrayname.length to refer to…you guessed it…the array length, but you still have to change the hardcoded length.

An ArrayList allows you to call functions that change the length of the array dynamically. On the fly. In the field. On a whim. Should the mood strike you.

For example, in the video below I’ve made a watery, ring object thing and then created an ArrayList of such watery, ring object things. Now I can create a new ring that’s part of the array every time I click the mouse. There are a whole bunch of functions that I can’t remember off hand, but the idea is that they give you the ability to change the number of index slots in the array at will.