- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to check the beginning of a string
To check the beginning of a string, use the startsWith() method.
Let’s say the following is our string.
String str = "demo";
Now, check for the substring “de” using the startWith() method in an if-else condition.
if(str.startsWith("de")) { System.out.println("The string begins with the word de"); } else { System.out.println("The string does not begin with the word de"); }
The following is the complete example with output
Example
public class Demo { public static void main(String[] args) { String str = "demo"; if(str.startsWith("de")) { System.out.println("The string begins with the word de"); } else { System.out.println("The string does not begin with the word de"); } } }
Output
The string begins with the word de
- Related Articles
- Java Program to remove whitespace from the beginning and end of a string
- Java Program to check the end of a string
- How to insert a string in beginning of another string in java?
- Java Program to Check if a String is Numeric
- Java program to check for URL in a String
- Java program to check string as palindrome
- Java program to check order of characters in string
- Java Program to Check if a string contains a substring
- Java Program to get the seconds since the beginning of the Java epoch
- How to match beginning of a particular string/line using Java RegEx
- Java Program to check whether one String is a rotation of another.
- Java program to check occurence of each character in String
- Java program to check occurence of each vowel in String
- Java program to check occurrence of each character in String
- Java program to check occurrence of each vowel in String

Advertisements