Cover Data Structures and Algorithms with Object-Oriented Design Patterns in Java
next up previous contents index

Extending Java Arrays

 

While the Java programming language does indeed provide built-in support for arrays, that support is not without its shortcomings: Array indices range from zero to n-1, where n is the array length. There is no array assignment operator. The size of an array is fixed once allocated.

One way to address these deficiencies is to define a new class with the desired functionality. We do this by defining an Array class with two fields as shown in Program gif. The first is an array of Java Objects and the second is an int which records the lower bound for array indices.

   program2674
Program: Array fields.


next up previous contents index

Bruno Copyright © 1998 by Bruno R. Preiss, P.Eng. All rights reserved.