I just announced the new Spring 5 modules in REST With Spring:

>> CHECK OUT THE COURSE

This article is part of a series:
• Java String.String()
• Java String.startsWith()
• Java String.codePointCount()
• Java String.codePointAt()
• Java String.concat()
• Java String.contains()
• Java String.copyValueOf()
• Java String.endsWith()
• Java String.format()
• Java String.getBytes()
• Java String.indexOf()
• Java String.intern()
• Java String.isEmpty()
• Java String.lastIndexOf()
• Java String.regionMatches()
• Java String.replace()
• Java String.replaceAll()
• Java String.split()
• Java String.startsWith()
• Java String.subSequence()
• Java String.substring()
• Java String.toLowerCase()
• Java String.toUpperCase()
• Java String.trim()
• Java String.valueOf()

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));
}

I just announced the new Spring 5 modules in REST With Spring:

>> CHECK OUT THE LESSONS