比如 Str="This  is a";

解决方案 »

  1.   

    单词间可能有 空格 tab 或 回车
      

  2.   

    Str="This is a";
    Str.length();返回一个整数9
      

  3.   

    使用java.util包下的StringTokenizer类可以你说的问题。。
      StringTokenizer st = new StringTokenizer("this is a test");
         while (st.hasMoreTokens()) {
             System.out.println(st.nextToken());
         }
     输出以下字符串: 
      this
      is
      a
      test也可以使用String类的split()方法
    String[] result = "this is a test".split("\\s");
    for (int x=0; x<result.length; x++)
       System.out.println(result[x]); 输出以下字符串: 
      this
      is
      a
      test
      

  4.   

    Str="This  is a";
    String[] s = Str.split("") ;
    int i = s.length() 
    就有i个单词啊