CHAPTER 7

ARRAYS

An array is by far the most powerful data structure in a programming language. This is the reason why it is in-built in all the HLLs, old as well as modern. We may not find any useful program without using an array.

7.1 Arrays in Java

An array is nothing but a sequential collection of items. We are allowed to refer to any item with the help of an index.

An item can be any of the following:

  • Any simple data type like int, char, and so on.
  • A string
  • An object of a given class
  • An array itself

The great strength of an array is that any particular element can be accessed with the help of the index. Just like C/C++, Java uses zero-based indexing. It means that index of the first element is always zero. It is not possible to define ...

Get Programming with Java 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.