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()
Course – LS – All

Get started with Spring and Spring Boot, through the Learn Spring course:

>> CHECK OUT THE COURSE
res – REST with Spring (eBook) (everywhere)
Comments are closed on this article!