Curriculum
Course: Java Basic
Login

Curriculum

Java Basic

Java Home

0/1

Java Introduction

0/1

Java Get Started

0/1

Java Syntax

0/1

Java Comments

0/1

Java Type Casting

0/1

Java Operators

0/1

Java Booleans

0/1

Java Switch

0/1

Java Break / Continue

0/1

Java Errors and Exception

0/1
Text lesson

startsWith()

Example

Determine whether the string begins with the given characters:

String myStr = "Hello";
System.out.println(myStr.startsWith("Hel"));   // true
System.out.println(myStr.startsWith("llo"));   // false
System.out.println(myStr.startsWith("o"));     // false

Definition and Usage

“The startsWith() method verifies if a string commences with the provided character(s).

Hint: Employ the endsWith() method to ascertain if a string concludes with the specified character(s).”

Syntax

public boolean startsWith(String chars)

Parameter Values

Parameter

Description

chars

A string that represents the character(s) to be examined.

Technical Details

Returns:

A boolean value is returned:

  • True: if the string commences with the specified character(s).
  • False: if the string does not commence with the specified character(s).