Programming and Problem Solving with Java

(やまだぃちぅ) #1
10.5 A r r a y s o f Objects | 497

10.5 Arrays of Objects


Although arrays with atomic components are very common, many applications require a col-
lection of composite objects. For example, a business may need a list of parts records, and a
teacher may need a list of students in a class. Arrays are ideal for these applications. We
simply define an array whose components are references to objects.


Arrays of Strings


Let’s define an array of strings, each of which is a grocery item. Declaring and creating an ar-
ray of objects is exactly like declaring and creating an array where the components are
atomic types.


String[] groceryItems = new String[10]; // Array of references to strings

Free download pdf