Lesson 14 of 34
Arrays: Many Values Together
9 min 25 XP
An array stores many values of the same type in order. Indexes start at 0, and arr.length gives the number of elements. An array's size can't change once it is created.
Example: edit me and press Run
Output Loading Java (first time takes a few seconds)
Press Run to see the result here.To fill an array from input: read the count n first, create new int[n], then read each value in a loop. Coding tests use this format all the time.
Example: edit me and press Run
Output Loading Java (first time takes a few seconds)
Press Run to see the result here.arr[arr.length] throws ArrayIndexOutOfBoundsException. The last index is arr.length - 1.