Page 466 - Introduction to Programming with Java: A Problem Solving Approach
P. 466
432 Chapter 10 Arrays and ArrayLists
with the following statement:
System.arraycopy(arr1, 0, arr2, 23, 3);
9. In the MovingAverage program, to shift in the other direction, the inner for loop header is: for (int d=days.length-1; d>0; d--)
The array element assignment statement in this loop is:
days[d] = days[d-1];
10. A histogram “bin” contains the number of occurrences of an event.
11. The Boolean expression that indicates that i has been found is:
(ids.length != 0 && i != ids.length)
12. The advantage of using class methods is that the sort method can be used with any passed-in array, not just on a specific instance variable array.
13. Java’s API sort method is in the Arrays class.
14. myArray[3] refers to the fourth row, which happens to be an array of eight double values.
15. True.
16. With an ArrayList, you can insert and delete elements anywhere in the sequence, and the list length grows and shrinks dynamically.
17. False. Normally, you specify no size for an ArrayList when you declare it. Apago PDF Enhancer
18. The get method’s return type is E, which refers to the type of each element in the ArrayList.
19. The element that is originally at position i shifts to the next higher index position.
20. Autoboxing takes place when a primitive is being used in a place that expects a reference.
21. prices.add(56.85);
22. System.out.println(prices);
23. An anonymous object is an object that’s instantiated but it’s not stored in a variable.
24. False. You can use a traditional for loop (or a for-each loop) to iterate through a collection of elements.
25. You should store your WeatherDay objects in a standard array. Rationale:
• There’s no need for the array to grow or shrink since the size is fixed at 365 (and standard arrays have a fixed size).
• Withsorting,you’llneedtoaccesstheobjectsquiteoften(andaccessiseasierwithstandardarrays).