There are three methods in the List interface that allow checking the presence and location of an element in the list:
- contains(E): It returns true if the provided element is present in the list.
- indexOf(E): It returns an index (position) of the provided element in the list. If there are several such elements in the list, the smallest index is returned – the index of the first element from the left that equals the provided element.
- lastIndexOf(E): It returns an index (position) of the provided element in the list. If there are several such elements in the list, the biggest index is returned – the index of the last element from the left that equals the provided element.
Here is the code that shows how to use these methods: ...