The method startsWith() is a convenience method that checks whether a String starts with another String. We can also pass the index of the first character to start checking from.

Available Signatures

public boolean startsWith(String prefix)
public boolean startsWith(String prefix, int toffset)

Example

@Test
public void whenCallStartsWith_thenCorrect() {
    String str = "foo";
    
    assertTrue(str.startsWith("f"));
    assertTrue(str.startsWith("oo", 1));
}
Next »
Java String.subSequence()
« Previous
Java String.split()
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 open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.