Java String.startsWith()

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

[source,java,gutter:,false]

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

Example

[source,java,gutter:,true]

@Test
public void whenCallStartsWith_thenCorrect() {
    String str = "foo";

    assertTrue(str.startsWith("f"));
    assertTrue(str.startsWith("oo", 1));
}