Java String endsWith 示例
时间:2020-02-23 14:35:13 来源:igfitidea点击:
字符串的endwith方法检查字符串是否以特定的后缀结尾。
它返回布尔数据类型。
方法语法:
public boolean endsWith(String suffix)
字符串EXTMISH示例:
package org.igi.theitroad; public class StringEndsWithExample { public static void main(String[] args) { String str = "theitroad"; if (str.endsWith("blog")) { System.out.println("String ends with blog"); } else { System.out.println("String does not end with blog"); } if (str.endsWith("BLOG")) { System.out.println("String ends with BLOG"); } else { System.out.println("String does not end with BLOG"); } } }
运行上面的程序时,我们将得到以下输出:
String ends with blog String does not end with BLOG
请注意endsWith方法是区分大小写的,如上面的示例所示