contains( ) method of ArrayList method

hi experts

I have a method listCounties() which returns a list of countyId fields.
I have a valueObject RegionVO which contains a field regionId.

Now My requirment is if "countyId" field  'contains' regionId or a part of regionId "do somtehing"
i have written something like this

Collection counties= listCounties();  //listCounties returns list of countyId

if (counties.contains(""+regionVO.getRegionId()))

do something
But counties is not getting recognized since its not being typecasted to the CountiesVO value object.

I can do somthing like this to get the individual elements but then i wont be ABLE to use "contains" method of Collection.
for (Iterator countyIt = counties.iterator();
                                                countyIt.hasNext(); ) {
                           CountiesVO countyVO = (CountiesVO);


any sugessions greatly appreciated

LVL 10
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You need to override equals
Since regionId would be, i guess, unique, you could use that as the basis of the equals implementation for CountiesVO
jaggernatAuthor Commented:
>>>>>You need to override equals

could you please elaborate .

thaNKS FOR prompt response
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

jaggernatAuthor Commented:
>>>>Since regionId would be, i guess, unique, you could use that as the basis of the equals implementation for CountiesVO

yes i thought about it. but i am not sure if i can use the "equals implementation"

this is the scenario:

region Id of RegionVO is value "3401"
countyId of CountyVO is value "34017" . so my requirment in that case would be if regionId is a "part of" countyId --> condition is satisfied-->do something.

any help appreciated
Question first:

>>Now My requirment is if "countyId" field  'contains' regionId

would countyId.equals(regionId) be true?
jaggernatAuthor Commented:
would countyId.equals(regionId) be true?

regionId can only be PART OF countyId

Ah we cross-posted. You're right. equals is not appropriate for 'fuzzy matching'. You'll simply have to iterate explicitly

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jaggernatAuthor Commented:
>>>>You'll simply have to iterate explicitly

can you please tell me how to do that???

Well you already posted some iterating code yourself. All you need to do is:

CountiesVO countyVO = (CountiesVO);
if (countyVO.getId().indexOf(regionVO.getId()) > -1) {
jaggernatAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.