开发手册 欢迎您!
软件开发者资料库

Java String endsWith() 方法

Java有一组可以用于字符串的内置方法。Java 字符串(String)操作常用操作,如字符串的替换、删除、截取、赋值、连接、比较、查找、分割等。本文主要介绍Java String endsWith() 方法。

Java 字符串方法

例如:

判断字符串是否以指定的字符结尾:

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

1、定义和用法

endsWith()方法检查字符串是否以指定的字符结尾。

提示:使用startsWith()方法判断字符串是否以指定的字符开头。

2、调用语法

public boolean endsWith(String chars)

3、参数说明

参数

描述

chars

String,代表要检查的字符

4、方法说明

返回值:

boolean值:如果字符串以指定字符结尾,则为true,

如果字符串不以指定的字符结尾,则为false

Java 字符串方法