📜  java-string-endswith(1)

📅  最后修改于: 2023-12-03 15:16:02.123000             🧑  作者: Mango

Java String endsWith()

Introduction

In Java, the endsWith() method is used to check whether a given string ends with the specified suffix. The method returns true if the string ends with the suffix, otherwise it returns false.

Syntax

The syntax of the endsWith() method is as follows:

public boolean endsWith(String suffix)

Here, suffix is the suffix to be checked in the given string.

Parameters

The endsWith() method takes one parameter, which is a string representing the suffix to be checked.

Return Value

The endsWith() method returns a boolean value, which is true if the string ends with the specified suffix, and false otherwise.

Example

Here is a simple example that demonstrates the usage of the endsWith() method:

String str1 = "Hello World!";
Boolean endsWith = str1.endsWith("ld!");

System.out.println(endsWith); // Output: true

In the example above, we created a string str1 and checked whether it ends with the suffix ld!. Since str1 ends with ld!, the endsWith() method returns true.

Conclusion

The endsWith() method is a useful method for checking whether a given string ends with a specified suffix. It is a simple and easy-to-use method that can greatly simplify string manipulation in Java.