When I say indexof() for an ArrayList I get the first occurunce of that object. How can I get all of the occurunces in an ArrayList of a specific object?
Thank you.
Printable View
When I say indexof() for an ArrayList I get the first occurunce of that object. How can I get all of the occurunces in an ArrayList of a specific object?
Thank you.
Do you know how to write a loop?
Yes but my knowladge for this purpose is not enough.
Can you provide a guidence or a simple example ?
Maybe like starting a new loop everytime with the index I have in an ArrayList over and over again?
The API is your friend - there are plenty of methods to let you loop over the items and check for Object equality of said items.
ArrayList (Java Platform SE 6)
I looked at this and couldnt find anything handy. I am trying to learn how to do it correctly as well.
No sorry, the only way I can think of is that boring looping over getting the index everytime, and starting a new loop until I can't find any other occurunce..
Read the entire API documentation for the List interface; especially the part that describes the subList( ... ) method.
kind regards,
Jos