- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 String startsWith() method example.
The startsWith(String prefix, int toffset) method of the String class tests if the substring of this string beginning at the specified index starts with the specified prefix.
Example
Live Demoimport java.lang.*; public class StringDemo { public static void main(String[] args) { String str = "www.tutorialspoint.com"; System.out.println(str); //The start string to be checked String startstr1 = "tutorialspoint"; String startstr2 = "tutorialspoint"; //Checks that string starts with given substring and starting index boolean retval1 = str.startsWith(startstr1); boolean retval2 = str.startsWith(startstr2, 4); //Prints true if the string starts with given substring System.out.println("starts with " + startstr1 + " ? " + retval1); System.out.println("string " + startstr2 + " starting from index 4 ? " + retval2); } }
Output
www.tutorialspoint.com starts with tutorialspoint ? false string tutorialspoint starting from index 4 ? true
- Related Articles
- Java String compareTo() Method example.
- Java String substring() Method example.
- Java String endsWith() method example.
- Java String equals() method example.
- Java String equalsIgnoreCase() method example.
- Java String format() method example.
- Java String getBytes() method example.
- Java String getChars() method example.
- Java String indexOf() method example.
- Java String intern() method example.
- Java String isEmpty() method example.
- Java String lastIndexOf() method example.
- Java String length() method example.
- Java String replace() method example.
- Java String split() method example.

Advertisements