Arraylist Contains() Question

A

ajay.kalyan

I am trying to add an object to an arraylist, but first I need to see
if the an object with a specified instance value already exists in the
arraylist. The Contains(obj) function checks the entire object but I
only need to check 1 instance variable in the object and return true or
false based on that.

My java experience tells me that it might have something to do with the
CompareTo() method, but I dont even know if the CompareTo method is
being used in the Contains() method. How would I go about creating a
Contains(string). Can I not override some method to get the desired
result or do I have to manually iterate the arraylist and check each
object?

Any help would be appreciated.

thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top