String str = "                  ";
if(str.trim().equalsIgnoreCase(""))
{
str = "hehe";
out.print(str);
}

解决方案 »

  1.   

    if (str == null || str.trim().length() == 0) {
     System.out.println("str is null");
    }
      

  2.   

    String str = "                  ";
    if(str.trim().equalsIgnoreCase(""))
    {
    str = "hehe";
    out.print(str);
    return;
    }
    else if(str.equalsIgnoreCase(""))
    {
    str = "haha";
    out.print(str);
    return;
    }
      

  3.   

    trim 过滤掉 前面 和后面的空格
      

  4.   

    String strSpace = "";
            String strEnter = "        ";        if(strSpace.equalsIgnoreCase(""))
            {
                System.out.println("Space for equalsIgnoreCase");
            }
            if(strSpace.equals(""))
            {
                System.out.println("Space for equals");
            }        if(strEnter.trim().equalsIgnoreCase(""))
            {
                System.out.println("Enter for equalsIgnoreCase");
            }
            if(strEnter.trim().equals(""))
            {
                System.out.println("Enter for equals");
            }
            System.out.println(strSpace.length());
            System.out.println(strEnter.length());
      

  5.   

    str ==null||str.length==0 ||str.equals("")
      

  6.   

    如果你只要判断它是不是空字符串(包括空格),就千万不要用trim方法,因为trim会去掉字符串前面和后面的所有小于33的字符,这样的话会去掉一些你想留的字符。但如果你觉得33以下的字符都可以算做空格的话,用trim方法最好了,否则用:
    if (str != null) {
    int i = 0;
    while (i < str.length()) {
        if (str.charAt(i) == ' ') {
            i++;
        }
    }
    if (i == str.length()) {
        System.out.println("str is empty");
    }
    }