Introduction to Arrays

Get a brief introduction to arrays in Java.

Introduction

Suppose a teacher has to check 1010 exam papers. Think in terms of a Java program. To keep track of the marks of 1010 different papers, we need ten different variables. What if we have 5050 different papers? That would be a lot of variables! How about we make one single variable to store the marks of 5050 different papers? Is this even possible? Yes, Java makes it possible.

Arrays in Java

An array is a block of memory that stores a collection of data elements of the same type under one name. It is a collection of related data.

If we have many elements of data of the same type, and we don’t need to name each one, then we use the array name and an index for the position of an item in the array.

The use of arrays allows multiple related items to be represented using a single variable.

đź“Ś Note: Remember when we discussed, indexing with the String type. The concept is the same.

Arrays in real life

In almost every school and college, a student is given a locker. A student has one locker to store his/her belongings. A student has a key to access the assigned locker.

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy