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 Meet Objects Refresher

Pranjal Agnihotri
Pranjal Agnihotri
4,187 Points

Related to Strings in Java

Which method in String will allow us to check that a given partial String is part of Main String or not

1 Answer

Richard Lambert
PLUS
Richard Lambert
Courses Plus Student 7,180 Points

Hello mate,

The String class has a method public boolean contains(CharSequence s). This method returns true if the string object contains the character sequence passed as the argument. CharSequence is an interface which is implemented by the String class, amongst others, hence you can pass a string as the argument when calling this method.

public class Test {
    public static void main(String[] args) {
        String content = "Is the word this in this?";
        String partial = "this";
        System.out.println(content.contains(partial));
    }
}

Hope this helps