Question: could i get help building these methods in java please iterator public java.util.ListIterator iterator () throws java.lang.UnsupportedOperationException, java.util.NoSuchElementException This method must be implemented using an
could i get help building these methods in java please
iterator
public java.util.ListIteratoriterator() throws java.lang.UnsupportedOperationException, java.util.NoSuchElementException
This method must be implemented using an inner class that implements ListIterator and defines the methods of hasNext(), next(), hasPrevious() and previous(). Remember that we should be able to call the hasNext() method as many times as we want without changing what is considered the next element.
Specified by:
iterator in interface java.lang.Iterable
Throws:
java.util.NoSuchElementException - Your next() method should throw NoSuchElementException if there are no more elements (at the end of the list and calling next() or at the beginning of the list and calling previous()).
java.lang.UnsupportedOperationException - You don't need to implement the ListIterator's remove(), add(), nextIndex() and previousIndex() and set() methods, throw UnsupportedOperationException if called.
------------------------------------------------------------
remove
public BasicDoubleLinkedListremove(T targetData, java.util.Comparator comparator)
Removes the first instance of the targetData from the list. Notice that you must remove the elements by performing a single traversal over the list. You may not use any of the other retrieval methods associated with the class in order to complete the removal process. You must use the provided comparator (do not use equals) to find those elements that match the target. Do not implement this method using iterators.
Parameters:
targetData - the data element to be removed
comparator - the comparator to determine equality of data elements
Returns:
data element or null
-------------------------------------------------
retrieveFirstElement
public T retrieveFirstElement()
Removes and returns the first element from the list. If there are no elements the method returns null. Do not implement this method using iterators.
Returns:
data element or null
---------------------------------
retrieveLastElement
public T retrieveLastElement()
Removes and returns the last element from the list. If there are no elements the method returns null. Do not implement implement this method using iterators.
Returns:
data element or null
----------------------------------
toArrayList
public java.util.ArrayListtoArrayList()
Returns an arraylist of the items in the list from head of list to tail of list
Returns:
an arraylist of the items in the list
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
