CMPT 166 Lecture Notes - Lecture 19: Ellipse
Document Summary
Like arraylistss, arrays are used to store multiple values of the same type. For example, here is an array containing four temperature measurements: float[] temps = { 2. 4, -1. 5, 3. 0, 2. 7 }; Notice the [] bracket in the type for temps that"s what tells processing this is an array. We can access individual elements of an array using []-bracket notation like this: println(temps[0]); // 2. 4 println(temps[1]); // -1. 5 println(temps[2]); // 3. 0 println(temps[3]); // 2. 7. If you try to access at value a position before the beginning of an array, or past the end, you get a run- time error: println(temps[-1]); // oops: arrayindexoutofboundsexception println(temps[4]); // oops: arrayindexoutofboundsexception. All processing (and java) arrays have a couple of important properties: once created, their size can never change. This is the major difference between arrays and arraylists. Recall that an arraylists can grow (and also shrink) in size as necessary.