目录

boolean endsWith(String suffix)

描述 (Description)

此方法测试此字符串是否以指定的后缀结尾。

语法 (Syntax)

以下是此方法的语法 -

public boolean endsWith(String suffix)

参数 (Parameters)

这是参数的细节 -

  • suffix - 后缀。

返回值 (Return Value)

  • 如果参数表示的字符序列是该对象表示的字符序列的后缀,则此方法返回true; 否则是假的。 请注意,如果参数为空字符串或等于此equals(Object)方法确定的String对象,则结果为true。

例子 (Example)

public class Test {
   public static void main(String args[]) {
      String Str = new String("This is really not immutable!!");
      boolean retVal;
      retVal = Str.endsWith( "immutable!!" );
      System.out.println("Returned Value = " + retVal );
      retVal = Str.endsWith( "immu" );
      System.out.println("Returned Value = " + retVal );
   }
}

这将产生以下结果 -

输出 (Output)

Returned Value = true
Returned Value = false
↑回到顶部↑
WIKI教程 @2018