+ 2
ArrayList question
How can I write a method which take parameter from an user by Scanner and then remove it from ArrayList. For example Array "Competitors" has a class "Person" and I would like to write lastName parameter in the console and remove it from the list by competitors.remove(...).
5 Réponses
+ 5
Can you show your code?😊
+ 1
In order to use competitors.remove() you need to give it a person object, and this must be considered equal to the element you want to remove, so you need to do this:
Create your Person class and override the equals() method to tell it how you consider two people equal (same first and last name?)
Your scanner can take in strings from the user and you can use these to construct a person instance. This means your Person class should have a constructor that takes your desired properties.
Should be good to go with this :)
0
Thanks a lot. It's an answer on my question. I will try tomorrow and tell you about results.
0
How do I play around with codes. .....seriously. ..started learning java last week but wen I try out......I get code error am puzzled. ..at least I want to create two. ....because things are confusing me.