The method contains() checks if a String contains another String. The method accepts a CharSequence. So, we can pass any of the implementing classes to it such as StringBuilder and StringBuffer.

Available Signatures

public boolean contains(CharSequence s)

Example

@Test
public void whenCallContains_thenCorrect() {
    String s = "abcd";
    
    assertTrue(s.contains("abc"));
    assertFalse(s.contains("cde"));
}

Next »
Java String.copyValueOf()
« Previous
Java String.concat()
November Discount Launch 2022 – Bottom
We’re finally running a Black Friday launch. All Courses are 30% off until next Friday:

>> GET ACCESS NOW

Generic footer banner
Comments are closed on this article!