Java String startsWith(String prefix) Method
In this tutorial you will learn how to use String.startsWith(String prefix) method. Tests if this string starts with the specified prefix value. It returns true if string starts with specified prefix, otherwise returns false value.
Refer below steps
boolean java.lang.String.startsWith(String prefix)
method tests if this string starts with the specified prefix.- Returns true if string starts with specified prefix, false otherwise
Java String.startsWith(String prefix) method example
package com.technicalkeeda.app; public class StringStartsWith { public static void main(String args[]) { String str = "technicalkeeda"; System.out.println("startsWith tech ? " + str.startsWith("tech")); System.out.println("startsWith Tech ? " + str.startsWith("Tech")); System.out.println("startsWith hello ? " + str.startsWith("hello")); System.out.println("startsWith technicalkeeda ? " + str.startsWith("technicalkeeda")); } }
Output
startsWith tech ? true startsWith Tech ? false startsWith hello ? false startsWith technicalkeeda ? true