How does "indexOf()" method work and where can it be used?
<p>I'm new to Java and is trying to learn the concept of iterator. I saw the code below from <a href="https://docs.oracle.com/javase/tutorial/collections/interfaces/list.html" rel="nofollow noreferrer">Java Tutorial Oracle</a>, however, I am struggling to understand the function of this method and how it could be used. Could someone provide me with an example of how to use this method as part of an working code and explain it to me how it works? </p>

<pre><code>public int indexOf(E e) {
    for (ListIterator&lt;E&gt; it = listIterator(); it.hasNext(); )
        if (e == null ? it.next() == null : e.equals(it.next()))
            return it.previousIndex();
    // Element not found
    return -1;
}
</code></pre>