Java apache commons-lang3 库 StringUtils 类 endsWith 方法


#Java Apache Commons 库#


为了方便阅读代码,本文中直接用了 println,这需要一些技巧,因为 import static java.lang.System.out.println; 是错误的。具体方法见 Java 如何静态导入 import static println

StringUtils 类的全路径:

import org.apache.commons.lang3.StringUtils;

endsWith 方法用于判断一个字符串是否以另一个字符串结尾。

println( StringUtils.endsWith(null, null) );      // true
println( StringUtils.endsWith("abc", "c") );      // true
println( StringUtils.endsWith("abc", "abc") );    // true
println( StringUtils.endsWith("abc", "abcd") );   // false
println( StringUtils.endsWith("abc", "ab") );     // false
println( StringUtils.endsWith("abc", null) );     // false
println( StringUtils.endsWith("abc", "C") );      // false

另有一个忽略大小写的方法:endsWithIgnoreCase 。


( 本文完 )