looking for object with certain local variable in an array list


I have an array list "comps" of an object components each component has a specific ID. I want to search the array for a components with a certain ID use it in a method flip.

for(int i=0; i<comps.size(); i++){
                    if(a==comps[i].sourceID){
                        comps[i].flip();
                    }
                }

I did this but it is not working as I expect it to do. I get an error saying "Array required, but ArrayList found"

---------------Answer---------------

You are using ArrayList which means that you can't use brackets for indexing, what you should do is:

for(int i=0; i<comps.size(); i++){
    if(a==comps.get(i).sourceID){
         comps.get(i).flip();
    }
}

Also I suggest you to look into streams, which makes it easier

---------------Answer---------------

You are trying to access array member by []. you should try comps.get(i)


Previous : How to save Emails of day from Outlook into a folder using python?
Next : Material UI autocomplete not being recognized