无涯教程-Java - boolean endsWith(String suffix)函数

68 阅读1分钟

此方法判断此字符串是否以指定的后缀(suffix)结尾。

boolean endsWith- 语法

public boolean endsWith(String suffix)

这是参数的详细信息-

  • suffix  -  后缀。

boolean endsWith - 返回值

  • 如果字符串是以suffix结尾,则返回true,否则为false。

boolean endsWith - 示例

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 );
   }
}

这将产生以下输出-

Returned Value=true
Returned Value=false

参考链接

www.learnfk.com/java/java-s…