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

.Contains Method

How can I implement the .contains method in order to produce a list of bad words. I have been stuck on this for while now.

1 Answer

Hi, what do u mean by a list of bad words? s The java string contains() method searches the sequence of characters in this string. It returns true if sequence of char values are found in this string otherwise returns false. so for example if u want to search if a String contains the word "ugly" u need to do something like this:

String badSentence = "Bob is very ugly but he knows java :D";
if(badSentence.contains("ugly"))
{
System.out.println("ugly has ben identified in the String");
}

hope this helps.