bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths

Loading lesson path

Learn/Java/Java Reference
Java•Java Reference

Java String endsWith() Method

❮ String Methods

Example

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

Definition and Usage

The endsWith() method checks whether a string ends with the specified character(s).

Tip

Use the startsWith() method to check whether a string starts with the specified character(s).

Syntax

public boolean endsWith(String
chars )

Parameter Values

ParameterDescription
charsA String , representing the character(s) to check for

Technical Details

Returns:A boolean value: true - if the string ends with the specified character(s) false - if the string does not end with the specified character(s)
  • true - if the string ends with the specified character(s)
  • false - if the string does not end with the specified character(s)

Previous

Java String copyValueOf() Method

Next

Java String equals() Method