Java String.endsWith()方法用法实例教程, 该方法返回一个true,如果参数表示的字符序列是由该对象表示的字符序列的后缀,否则返回false
描述
java.lang.String.endsWith() 方法返回的测试该字符串是否以指定后缀sffix结束
声明
以下是声明java.lang.String.endsWith()方法
public boolean endsWith(String suffix)
参数
-
suffix -- This is the suffix.
返回值
该方法返回一个true,如果参数表示的字符序列是由该对象表示的字符序列的后缀,否则返回false.
package com.z3;
-
public class EndWithTest { public static void main(String[] args) { String str = "www.yiibai.com"; System.out.println(str); // the end string to be checked String endstr1 = ".com"; String endstr2 = ".org"; String endstr3 = "yiibai"; String startstr4 = "www"; // checks that string str ends with given substring boolean retval1 = str.endsWith(endstr1); boolean retval2 = str.endsWith(endstr2); boolean retval3 = str.endsWith(endstr3); boolean retval4 = str.startsWith(startstr4); // prints true if the string ends with given substring System.out.println("ends with " + endstr1 + " ? " + retval1); System.out.println("ends with " + endstr2 + " ? " + retval2); System.out.println("ends with " + endstr3 + " ? " + retval3); System.out.println("ends with " + startstr4 + " ? " + retval4); } }