Exercises

20.3 (Explain Notation) Explain the use of the following notation in a Java program:

public class Array<T> { }

20.4 (Generic Method selectionSort) Write a generic method selectionSort based on the sort program of Fig. 19.4. Write a test program that inputs, sorts and outputs an Integer array and a Float array. [Hint: Use <T extends Comparable<T>> in the type-parameter section for method selectionSort, so that you can use method compareTo to compare the objects of the type that T represents.]

20.5 (Overloaded Generic Method printArray) Overload generic method printArray of Fig. 20.3 so that it takes two additional integer arguments, lowSubscript and highSubscript. A call to this method prints only the designated portion of the array. ...

Get Java™ How To Program (Early Objects), Tenth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.