Java Top

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

>> CHECK OUT THE COURSE

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()
Java bottom

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

>> CHECK OUT THE COURSE
Comments are closed on this article!