java-String类中的各字符串判断,包括" "和null的区别

package com.day7.one;

public class DemoString1 {

  /**

  * @param args

  * 1.boolean equals(Object obj) 比较字符串的内容是否相同,区分大小写

  * 2.boolean equalsIgnoreCase(String str) 比较字符串内容是否相同,不区分大小写

  * 3.boolean contains(String str) 判断大字符串中是否包含小字符串

  * 4.boolean startWith(String str) 判断字符串中是否以某个字符串开头的

  * 5.boolean endsWith(String str) 判断字符串中是否以某个字符串结尾的

  * 6.boolean isEmpty() 判断字符串是否为空

  */

  public static void main(String[] args) {

    String s1="KobeBryant";

    String s2="";

    String s3=null;

    System.out.println(s1.isEmpty()); //false

    System.out.println(s2.isEmpty()); //true

    System.out.println(s3.isEmpty()); //异常

  /*

  * ""和null的区别

  * ""是字符串常量,同时也是一个String类的对象,既然是对象当然可以调用String类中的方法

  * null是空常量,不能调用任何的方法,否则会出现空指针异常,null可以给任意的引用数据类型赋值

  * */

  }

}