Pick an interface in the JDK, describe the method(s) that interface requires, and describe a good use of it.
Thanks for the question, Here is one interface List which is inside the java.util package. ================================================================================================ List Interface: This interface is an extension of the collection interface. Elements in the List can be inserted, accessed, or deleted by their position in the list, starting from index 0. A few methods of this interface include: 1. add(): This method takes 2 arguments as input, the first one the index at which you want to add the element, and the second one is the element itself. This function will simply add the element at the specified location(index) in the list, and will not return anything. 2. get(): This method takes 1 argument as input, that is the index at which you want to fetch the element in the list from. And will return the fetched element as output. 3. indexOf(): This method takes 1 argument as input, that is the element to search for, and will return the index of that element at which it is found in the list if found, and will return -1 otherwise. 4. lastIndexOf(): This method works pretty much the same as the previous method. The only difference is, if the element is found in the list more than once, the previous method returns the index of the first appearance of the element in the list, whereas, this method returns the index of the last appearance of the element in the list. 5. remove(): This method takes 1 argument as input, that is the index from which the element to delete in the list, and will return the deleted element as outpu. 6. subList(): This method takes 2 arguments as input, the start index, and the end index, and will return the list of elements from start index to end index as output. 7. listIterator(): This method if no parameter is passed as input, returns the iterator, pointing to the start of the list. Whereas if an integer parameter is passed as input, will now return the iterator, pointing to the index specified as input.
Concrete class that implements List interface is ArrayList.
thank you !
Get Answers For Free
Most questions answered within 1 hours.