Saturday, November 10, 2012

Java Exercise #48: Generic Sort of Comparables

The problem is to write a generic method to sort an array of Comparable objects. The objects are sorted using the compareTo() method of the Comparable interface.

Exercise: Write a program that sorts any generic array of objects that implements Comparable interface


Sorted Integer Objects: 2 3 4 
Sorted Double Objects: -22.1 1.4 3.4 
Sorted Character Objects: J a r 
Sorted String Objects: Fred John Tom 



Download Code: Generic Sort

No comments:

Post a Comment