Java One Dimensional (1D) Arrays
Arrays are critical building blocks in Java, and many other programming language. The allow us to store a lot of data in a single variable and are an efficient way of using data within our programs. In this lesson you will learn:
- How to create empty and populated arrays
- How to determine the length of an array
- How to access individual and multiple elements within an array
- How to modify individual and multiple elements within an array
An array can be described as a variable that contains one or many values of a single data type. Each value within an array is called an element, and each elements place in the array is defined by its index position. The structure of a 1 dimensional array (or 1D array) is similar to a list or a simple spreadsheet with one row of data. The following table of student grades illustrates how data within an array is stored in seperate elements that have a unique index number, starting from 0:
Index: | 0 | 1 | 2 | 3 | 4 |
Data: | 82 | 76 | 65 | 92 | 55 |
This array has 8 elements, one for each student grade. Each element contains an integer value and can be accessed using its index number.
What you will learn
In this lesson we will cover how and why you might use 1 Dimensional arrays. We will discuss the structure of 1D arrays and how to access elements to return their value, to manipulate their value in a variety of ways, and how to reassign their value.