Originally Posted by
nafty
Hi,
I am interested to find all the indexes where an element that I specify occurs in an ArrayList. Is there already a method for this? I see in the documentation that there are two similar methods that return the index of the first appearance of the element (indexOf) and the last index of (lastIndexOf). Is there a method to return all indexes? Am I missing something? Or do I need to write my own code to achieve this?
On a probably-separate note: what is an Iterator? Does that have anything to do with this?
Basically what I want is to have returned to me a list of all the indexes where an object appears in a list, e.g. <pre> List<Elements> foundElements = variableArrayList.getAllIndexesOf(varElement);</pre>
Thanks much,
-Daniel
A Iterator is just an manner to iterate over a collection. When you look to the API it has no methods to say when a element is in the collection.