5 Working with Array in Java

5.1 INTRODUCTION

An array is a data structure which can store multiple elements of same type under one name. In other words, an array is a collection of variables of the same type, all of which are referred by a common name. The specific element of an array is accessed by an index. One single variable can store only one value at a time. In order to work with multiple data items at the same time, all of which have some common features, e.g., age of all students, salary of all employees, etc. then instead of creating separate variable for each data item an array can be used.

The declaration of an array is done in the following way:

int arr [];

By the above statement an array is named as arr . While declaring an array, ...

Get Java Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.