Skip to Main Content
| Brooklyn College Library & Academic IT |CISC Department

CISC 3130 Data Structures: Arrays

Professor Chuang Spring 2020 OER

Introduction

Definition: An assemblage of items that are randomly accessible by integers, the index.

An array, as the Java programming language defines, is a container that holds a fixed number of values of a single type. We will be using this definition in this class. The length of the array is established when the array is created. Each item in an array is called an element, each of which is is accessed by a numerical index. As shown in the illustration, the index begins with 0. The 9th element, for example, would therefore be accessed at index 8.

 

 

References: 

Black, Paul E. (2016-11-16). Pieterse, Vreda; Black, Paul E. (eds.). "array". Dictionary of Algorithms and Data Structures. National Institute of Standards and Technology. Retrieved from: https://xlinux.nist.gov/dads/HTML/array.html

Concept

Arrays are fixed memory allocation in memory. 

Array Data Structure

Accessing arrays is like addresses for buildings. Because of fixed positions, you can access an element by it's position.

Access elements by position

 

 

 

Pros/Cons

Pros:

  • Easy to access elements when you know the position

Cons:

  • Fixed length, can't add more elements than the maximum number set

Java Implementation

Creating an array in Java involves distinct steps such as:

Other properties of arrays implemented in Java:

  • Arrays start with index 0. Refer to that first element with position 0 as a[0]
  • Fixed length - once you create an array the length is fixed. You refer to length of a[] with a.length