Question: Please help as List Methods In this part of the assignment, you'll write several generic List methods that make use of the Comparator interface. Write
Please help as
List Methods In this part of the assignment, you'll write several generic List methods that make use of the Comparator interface. Write these all in a class named CompareLists in CompareLists.java. 1. Write a generic method minimum that takes a List and a Comparator and returns the smallest element in the list according the comparator, or null if the list is empty. Assume there are no null elements in the list. 2. Write an overload of the generic method minimum that takes an E[] (an array of E) and a Comparator and returns the smallest element in the array according the comparator, or null if the array is empty. Assume there are no null elements in the array. 3. Write a generic method greater Than that takes a List , a Comparator , and an element E, and returns a new List containing just the elements that are larger than the given element according to the given comparator. Assume there are no null elements in the array. 4. Write a generic method inOrder that takes a List and a Comparator and returns true if the elements in the array list are in increasing order according to the comparator, and false otherwise. If any of the elements in the list are null, throw an IllegalArgumentException with a message that says "null value in list". 5. Write an overload of the generic method in0rder that takes an E[] (an array of E) and a Comparator and returns true if the elements in the array list are in increasing order according to the comparator, and false otherwise. If any of the elements in the list are null, throw an IllegalArgumentException with a message that says "null value in array". 6. Write a generic method merge that takes a Comparator and two List , each of which is in increasing order according to the given comparator. It should return a new List containing all the elements from both lists in increasing order. If any of the elements in either list are null, throw an IllegalArgumentException with a message that says "null value in first list" if it came from the first one, and "null value in second list" if it came from the second one. Hint: write and tes method at a time!
Step by Step Solution
3.54 Rating (157 Votes )
There are 3 Steps involved in it
All the methods has been written as per requirement Code import javautil class CompareLists public E ... View full answer
Get step-by-step solutions from verified subject matter experts
