How can I check if value exist in ArrayList by its index?
Java offers contains(Object) method, but no contains(Integer index) method
Thank you
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Not at all sure what your question is. You talk about seeing if an entry “exists” but then you talk about Java lacking a
remove(Object index)method.Regarding remove: There’s the remove(int) method on the
Listinterface implemented byArrayList. (JavaLists are indexed byint, not byObject.)Regarding whether an entry “exists” at a given index, if the list’s
size()method is greater than the index (and the index is non-negative), then there’s an entry at that index: