#Removing object from arrayList if name.equals()

15 messages · Page 1 of 1 (latest)

deft vortex
#

Basically I want to remove and object from an arrayList if the name equals with the one I have stored in a variable, I know there is something called removeIf() but its not working for me at all. Any ideas?

keen hillBOT
#

This post has been reserved for your question.

Hey @deft vortex! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

unborn wraith
#

you're not using it right

#

removeIf takes a predicate that takes the type of element in the arraylist, returns true if it should be removed and false if not

#

how does your code look

deft vortex
#

the method looks like this

#

I saw someone using the removeIf to check if n > 10 so I tried it also with my case

unborn wraith
#

you dont need that loop around it

#

just have the removeIf there and it should be fine

#

putting a loop around it will cause it to crash because you're modifying the list as you iterate over it

#

which ArrayList does not like

deft vortex
#

Okay Lemme try

#

It works, thanks! :)

keen hillBOT
# deft vortex It works, thanks! :)

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.