使用startsWith与endsWith需注意的点

337 阅读1分钟

使用startsWith与endsWith需注意的点

  1. 字符串不能颠倒
  2. 字符串需要判空
public class Test {

    public static void main(String[] args) {

        String a = "hello world";
        String b = "world";

        String c = "";

        LogJava.e(a.endsWith(b) + ""); //正常使用 true

        LogJava.e(a.endsWith(c) + ""); //c为空字符串 true
        LogJava.e(a.startsWith(c) + "");//c为空字符串 true

    }

}