Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Objects (Retired) Meet Objects Refresher

Chaz Hall
Chaz Hall
1,970 Points

.contains Explanation

I'm trying to understand the .contains. I understand that it compares one string to another word(s) in another string, but what other functions does it have? Thanks!

1 Answer

Rob Bridges
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 Points

Hey Chaz,

Really when speaking about Strings that is the only thing that it does, checks and see if the sub string that we pass as an argument is contained in the main string.

Though there is a contains method on ArrayLists that let us check if an Object is contained in that arrayList.

And maps have something similar with the containsKey or ContainsValue, but essentially they all do the same check.

They check to see if the passed argument is contained in the object that we passed in.

Thanks, hope this helps.