Chapter 7 Arrays Goals This chapter introduces the Java array for storing collections of many objects. Individual elements are referenced with the Java subscript operator []. After studying this chapter you will be able to declare and use arrays that can store reference or primitive values implement methods that perform array processing 7.1 The Java Array Object Java objects store collections of elements. They allow a large number of elements to be array conveniently maintained together under the same name. The first element is at index 0 and the second is at index 1. Array elements may be any one of the primitive types, such as or int Array elements can also be references to any object. double. The following code declares three different arrays named and It also balance, id, tinyBank. initializes all five elements of those three arrays. The subscript operator provides access to [] individual array elements. // Declare two arrays that can store up to five elements each double[] balance = new double[5]; String[] id = new String[5]; // Initialize the array of double values balance[0] = 0.00; balance[1] = 111.11; balance[2] = 222.22; balance[3] = 333.33; balance[4] = 444.44; // Initialize all elements in an array of references to String objects id[0] = "Bailey"; id[1] = "Dylan"; id[2] = "Hayden"; id[3] = "Madison"; id[4] = "Shannon"; The values referenced by the arrays can be drawn like this, indicating that the arrays balance, and store collections. is a collection of primitive values; is a collection of id, balance id references to String objects.
Chapter 7 Arrays Goals This chapter introduces the Java array for storing collections of many objects. Individual elements are referenced with the Java subscript operator []. After studying this chapter you will be able to declare and use arrays that can store reference or primitive values implement methods that perform array processing 7.1 The Java Array Object Java array objects store collections of elements. They allow a large number of elements to be conveniently maintained together under the same name. The first element is at index 0 and the second is at index 1. Array elements may be any one of the primitive types, such as int or double. Array elements can also be references to any object. The following code declares three different arrays named balance, id, and tinyBank. It also initializes all five elements of those three arrays. The subscript operator [] provides access to individual array elements. // Declare two arrays that can store up to five elements each double[] balance = new double[5]; String[] id = new String[5]; // Initialize the array of double values balance[0] = 0.00; balance[1] = 111.11; balance[2] = 222.22; balance[3] = 333.33; balance[4] = 444.44; // Initialize all elements in an array of references to String objects id[0] = "Bailey"; id[1] = "Dylan"; id[2] = "Hayden"; id[3] = "Madison"; id[4] = "Shannon"; The values referenced by the arrays can be drawn like this, indicating that the arrays balance, and id, store collections. balance is a collection of primitive values; id is a collection of references to String objects.
227Sum15.docx