1.
if (s.equals(""))
{
//为空
}
2.if (s.length()==0)
{
//为空
}
3.==是用来判断对象句柄地址的。
4.equal是用来判断句柄内容的。

解决方案 »

  1.   

    equals==是判断指针是否相等,不是判断字符串的内容
      

  2.   

    String str = "";
    if(str==null || str.equals(""))
    {
    .....
    }
    null用==,不然用equals或者compareTo
      

  3.   

    String str = "";
    if(str==null || str.equals(""))
    {
    .....
    }
    null用==,不然用equals或者compareTo
      

  4.   

    if ( s == null){
    }
    if(s.length() == 0){
    }
    这两种很多地方都要用.
      

  5.   

    str == null || str.length() < 1
      

  6.   

    str==null || str.equals(""))
    再澄清一个概念:
    如果str==null说明str还未定义内容。此时,谈不上是否为空。
    str="",说明str是个空字符串。只不过长度为0。这是不同的概念。
      

  7.   

    String s;
    ...
    if(s==null)
    {
     //为null;
    }
    if (s.equals(""))
    {
    //为空字符串;
    }
    if (s.length()==0)
    {
    //为空字符串;
    }
    ==是用来判断对象句柄地址的。
    equal是用来判断句柄内容的。
    想要实现equal的效果可以使用这样
    s.intern=="".intern