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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.