OBJECTIVES
In this chapter you will study:
This chapter shows you how to work with arrays. You will learn how to define and manipulate both single and multidimensional arrays. In this chapter, as in others, we will develop real working programs to illustrate using Java arrays.
NOTES
COBOL uses the terms single-level table; Java uses one-dimensional array.
In keeping with the spirit of Java, here we will use array and dimension.
This chapter begins with the declaration and population of one-dimensional arrays, then illustrates how to declare and populate two-dimensional arrays. The examples use both numeric and string data values.
The chapter also describes how to search an array using Java and how to pass arrays as arguments to methods.
You will see that, although internally Java treats array processing somewhat differently than COBOL, Java array handling looks a lot like COBOL table processing to the programmer. Of course, we will continue to point out significant differences between Java and COBOL and the pitfalls to avoid when writing Java from a COBOL programmer's perspective.
This chapter assumes you understand the following:
COBOL:
Defining one & two level tables
Initializing one & two level tables
Table lookup techniques
Using subscripts and indexes
Perform-varying statement
Java:
OO concepts (Chapter 2)
Java program structure (Chapter 3)
Defining data (Chapter 4)
Decision making (Chapter 6)
Looping (Chapter 7)
DECLARING ONE-DIMENSIONAL ARRAYS
We begin our discussion of one-dimensional arrays by looking at loan processing for the Community National Bank (CNB).