Array Basics

In this lesson, we will explore how to declare and create an array, and how to reference its elements.

Picturing an array

Creating many distinctly named variables is not a reasonable way to represent a group of data, an array will enable us to conveniently group numerous items together and yet have the ability to reference any individual item in the group. We can picture an array much as we pictured the string in an earlier chapter. Just as we do for the characters of the string, we number the items in an array with consecutive integers beginning with zero, and we call each of these integers an index. The figure given below illustrates an array of characters. Although this depiction of an array is identical to our depiction of a string, strings and arrays are different things in Java.

Get hands-on with 1400+ tech skills courses.