目录

boolean endsWith(String suffix)

描述 (Description)

如果此字符串以指定的suffix结尾,则java.lang.String.endsWith()方法返回测试。

声明 (Declaration)

以下是java.lang.String.endsWith()方法的声明

public boolean endsWith(String suffix)

参数 (Parameters)

suffix - 这是后缀。

返回值 (Return Value)

如果参数表示的字符序列是此对象表示的字符序列的后缀,则此方法返回true,否则返回false。

异常 (Exception)

NA

例子 (Example)

以下示例显示了java.lang.String.endsWith()方法的用法。

package com.iowiki;
import java.lang.*;
public class StringDemo {
   public static void main(String[] args) {
      String str = "www.iowiki.com";
      System.out.println(str);
      // the end string to be checked
      String endstr1 = ".com";
      String endstr2 = ".org";
      // checks that string str ends with given substring
      boolean retval1 = str.endsWith(endstr1);
      boolean retval2 = str.endsWith(endstr2);
      // prints true if the string ends with given substring
      System.out.println("ends with " + endstr1 + " ? " + retval1);
      System.out.println("ends with " + endstr2 + " ? " + retval2);
   }
}

让我们编译并运行上面的程序,这将产生以下结果 -

www.iowiki.com
ends with .com ? true
ends with .org ? false
↑回到顶部↑
WIKI教程 @2018