
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
How to check if the string begins with specific substring in Java?
A String class can be used to represent the character strings, all the string literals in a Java program are implemented as an instance of a String class. The Strings are constants and their values cannot be changed (immutable) once created.
We can use the startsWith() method of String class to check whether a string begins with a specific string or not, it returns a boolean, true or false.
Syntax
public boolean startsWith(String prefix)
Example
public class StringStartsWithSubStringTest { public static void main(String[] args) { String str = "WelcomeToTutorialsPoint"; if(str.startsWith("Welcome")) { System.out.println("Begins with the specified word!"); } else { System.out.println("Does not begin with the specified word!"); } } }
Output
Begins with the specified word!
- Related Articles
- How to check if the string ends with specific substring in Java?
- Check if string begins with punctuation in JavaScript
- How To Check If Cell Begins Or Ends With A Specific Character In Excel?
- How to check if string or a substring of string starts with substring in Python?
- Find if a string begins with a specific set of characters in Arduino
- Java Program to Check if a string contains a substring
- How to check if string or a substring of string ends with suffix in Python?
- How to check if the string contains the specific word?
- How to check if a string contains a substring in Golang?
- Java program to check if a Substring is present in a given String
- Check if substring present in string in Python
- How do we check if a String contains a substring (ignoring case) in Java?
- How can we check if specific string occurs multiple times in another string in Java?
- How to check if a string contains a specific sub string?
- How to check if a substring is contained in another string in Python

Advertisements