Question: Hi #Java I have to write in Java generic method with ArrayList, LinkedList, HashSet and TreeSet . All methods need to be generic and need
Hi
#Java
I have to write in Java generic <> method with ArrayList, LinkedList, HashSet and TreeSet . All methods need to be generic and need to test them
Please help me with this task
With ArrayList :
1. A generic method that replaces the third element of the ArrayList passed in the argument with another element (also passed in the argument).
2. A generic method that will increase the size of a given ArrayList by the specified value.
3. A generic method that will trim the capacity of the ArrayList to the number of elements it currently has.
4. A generic method that will clear the given ArrayList.
With LinkedList
1. A generic method that inserts a given item into the selected LinkedList index
2. A generic method that checks whether a given element exists in LinkedList
3. A generic method that will check whether a given LinkedList is empty or not
4. A generic method that will return a LinkedList of boolean, the method is to compare the elements of two LinkedLists - if two LinkedLists have all, e.g. 3 elements the same, then the LinkedList should look like this: [true, true, true].
With HashSet:
1. A generic method that will compare two sets and return a collection of only those items that are common to both sets
2. A generic method that will compare two HashSets - the method is supposed to return boolean.
TreeSet:
1. A method that will return and remove the last element of the TreeSet passed in the argument;
2. A method that will return an element lower than the object specified in the argument. In the Argument, you must also specify the given TreeSet
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
