用正则表达式判断!用java.util.regex.Matcher和java.util.regex.Pattern包

解决方案 »

  1.   

    String str="abcd abcd";
    if(str.indexOf(" ")!=-1) System.out.print("There are spaces!"):
      

  2.   

    frhwxx(笑对^_^人生) :
    能不能详细一点啊?我是新手~~
    可以把代码贴出来么?谢谢。
      

  3.   

    String test_blank = "asd    sdlfj";
    String flag="false";
    for(int i=0;i<test_blank.length();i++){
      if(test_blank.substring(i,i+1).equals(" ")){
      flag="true";
      }  
    }
     if(flag=="true"){
      out.println("有空格"); 
     }
      

  4.   

    用indexOf(“”) 进行判断比较方便
      

  5.   

    public class Test
    {
    public static void main(String[] args)
    {
    String s=" classjava  boy";
    if(s.trim().lastIndexOf(" ")==-1)
    System.out.println("字符串中间没有空格");
    else
    System.out.println("字符串中间有空格");
     
     
    }
    }
      

  6.   

    public class Test
    {
    public static void main(String[] args)
    {
    String s=" classjava  boy";
    if(s.trim().lastIndexOf(" ")==-1)
    System.out.println("字符串中间没有空格");
    else
    System.out.println("字符串中间有空格");
     
     
    }
    }正解!!!