Page 459 - Introduction to Programming with Java: A Problem Solving Approach
P. 459

                §10.8 Sorting an Array
12. We elected to use class methods to implement our sort algorithm. What is an advantage of that? 13. Java’s API sort method is in what class?
§10.9 Two-Dimensional Arrays
14. We have said that a two-dimensional array is an array of arrays. Consider the following declaration:
double[][] myArray = new double[5][8];
In the context of the expression, array of arrays, what does myArray[3]mean?
§10.10 Arrays of Objects
15. In creating an array of objects, you have to instantiate the array object, and you must also instantiate each
element object that’s stored in the array. (T / F)
§10.11 The ArrayList Class
16. How is an ArrayList more versatile than an array?
17. To avoid runtime errors, you must always specify the size of an ArrayList when you declare it. (T / F) 18. What is the return type of the ArrayList class’s get method?
19. If you call the ArrayList method, add(i, x), what happens to the element originally at position i?
§10.12 Storing Primitives in an ArrayList
20. Specifically, under what circumstances does autoboxing take place?
21. Write one statement that appends the double value, 56.85, to the end of an existing ArrayList called
prices.
Apago PDF Enhancer
22. Write one statement that displays all of the values in an ArrayList of Doubles called prices. Put the complete list in square brackets and use a comma and a space to separate different values in the list.
§10.13 ArrayList Example Using Anonymous Objects and the For-Each Loop
23. What is an anonymous object?
24. You must use a for-each loop, and not a traditional for loop, whenever you need to iterate through a
collection of elements. (T / F)
§10.14 ArrayLists Versus Standard Arrays 25. Given:
• YouhaveaWeatherDayclassthatstoresweatherinformationforasingleday.
• You’dliketostoreWeatherDayobjectsforawholeyear.
• TheprimarytaskofyourprogramissortingWeatherDayobjects(e.g.,sortbytemperature,sortby
wind speed, and so on).
How should you store your WeatherDay objects—in an ArrayList or in a standard array? Provide a rationale for your answer.
Exercises
1. [after §10.2] The index number of the last element in an array of length 100 is .
2. [after §10.3] Declare an array named scores that holds double values.
3. [after §10.3] Provide a single initialization statement that initializes myList to all 1’s. myList is a 5-element array of int’s.
Exercises 425
 
































































   457   458   459   460   461