📅  最后修改于: 2023-12-03 15:16:02.123000             🧑  作者: Mango
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
.
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.
The endsWith()
method takes one parameter, which is a string representing the suffix to be checked.
The endsWith()
method returns a boolean value, which is true
if the string ends with the specified suffix, and false
otherwise.
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
.
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.