Question: Practice Program: Write a similar program in IntegerAbsComparator.java that compares Integer objects to order them by absolute value. Finally, we will sort some arrays of

Practice Program: Write a similar program in IntegerAbsComparator.java that
compares Integer objects to order them by absolute value.
Finally, we will sort some arrays of String and Integer values using the sort methods in java.util.Arrays (API Javadoc). That class provides several sort methods, but we will make use of two of them:
Arrays.sort(Object[] a); which sorts the items in a by a natural ordering (provided by the compareTo method of the objects), and Arrays.sort(T[] a, Comparator c);
which sorts according to the compare method of the Comparator parameter. That crazy syntax just says that the Comparator has to be able to take objects of type T as its parameters. Which makes sense, since the compare method needs to compare objects of type T and will probably need access to its instance variables and/or methods to achieve this. You will also want to remember and make use of Arrays.toString for easy printing of your array contents.
Practice Program: Write a Java application in a class Sorting.java that creates arrays of Integer and String objects, and sorts them first using the natural ordering, then using the alternate orderings by the Comparators we have worked with in this lab.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!