在java中,要判断某个字符串是否以某字符串结尾,使用字符串的方法endsWith可实现
boolean java.lang.String.endsWith(String suffix)
判断当前字符串是否以后缀suffix结尾,返回真或假,真表示以suffix结尾,假表示不以suffix结尾
举例:
String s = "helloWorld";
if (s.endsWith("World")) {
System.out.println("字符串以World结尾");
} else {
System.out.println("字符串不是World结尾");
}
输出结果为:字符串以World结尾