Java startsWith() Method
-- Learning not just technology, but dreams!
- Home
- HTML
- JavaScript
- CSS
- Vue
- React
- Python3
- Java
- C
- C++
- C#
- AI
- Go
- SQL
- Linux
- VS Code
- Bootstrap
- Git
- Local Bookmarks
Java Tutorial
Java Tutorial Java Introduction Java Development Environment Setup Java Basic Syntax Java Comments Java Objects and Classes Java Basic Data Types Java Variable Types Java Variable Naming Rules Java Modifier Types Java Operators Java Loop Structures β for, while and doβ¦while Java Conditional Statements β ifβ¦else Java switch case Statement Java Number & Math Class Java Character Class Java String Class Java StringBuffer and StringBuilder Class Java Arrays Java Date and Time Java Regular Expressions Java Methods Java Constructors Java Stream, File and IO Java Scanner Class Java Exceptions
Java Object-Oriented
Java Inheritance Java Override/Overload Java Polymorphism Java Abstraction Java Encapsulation Java Interfaces Java Enum Java Package Java Reflection
Java Advanced Tutorial
Java Data Structures Java Collections Framework Java ArrayList Java LinkedList Java HashSet Java HashMap Java Iterator Java Object Java NIO Files Java Generics Java Serialization Java Networking Java Sending Email Java Multithreading Java Applet Basics Java Documentation Comments Java Examples Java 8 New Features Java MySQL Connection Java 9 New Features Java Quiz Java Common Libraries
Java Character Class Java StringBuffer and StringBuilder Class
Java startsWith() Method
The startsWith() method is used to check whether a string starts with a specified prefix.
Syntax
public boolean startsWith(String prefix, int toffset) or public boolean startsWith(String prefix)
Parameters
- prefix -- The prefix.
- toffset -- The position in the string to start searching from.
Return Value
Returns true if the string starts with the specified prefix; otherwise, returns false.
Example
public class Test {
public static void main(String args[]) {
String Str = new String("www.");
System.out.print("Return value :");
System.out.println(Str.startsWith("www"));
System.out.print("Return value :");
System.out.println(Str.startsWith("tutorial"));
System.out.print("Return value :");
System.out.println(Str.startsWith("tutorial", 4));
}
}
The result of the above program execution is:
Return value :true
Return value :false
Return value :true
YouTip