String str = "The indictment said the defendants "
               + "had collected geographical data indicating "
               + "thousands of people would be killed in the "
               + "chemical blast";
怎么用StringTokenizer
解析到StrAry数组里
谢谢

解决方案 »

  1.   


    public class Test 
    {
    public static void main(String[] args)
    {
    String str =  "The indictment said the defendants "
                    + "had collected geographical data indicating "
                    + "thousands of people would be killed in the "
                    + "chemical blast";
    String[] strAry = str.split("\\s");

    // 打印出来
    for (int i = 0; i < strAry.length; i ++)
    System.out.println(strAry[i]);

    }}
      

  2.   

    运行如下:
    F:\>javac Test.javaF:\>java Test
    The
    indictment
    said
    the
    defendants
    had
    collected
    geographical
    data
    indicating
    thousands
    of
    people
    would
    be
    killed
    in
    the
    chemical
    blastF:\>
      

  3.   

    不好意思我问个比较那个点的问题.........StringTokenizer是什么意思
      

  4.   

    java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("\\s");
    String str;//你给定
    String arr = pattern.split(str);
    String  token  字符串节点 分解。
    java.util.StringTokenizer str = java.util.StringTokenizer(str," ");//空格分隔
      

  5.   

    String[] arg;
    int count=0;
    StringTokenizer str1=new StringTokenizer(str," ");
    arg=new String[str1.countTokens()];

    while(str1.hasMoreTokens())
    {
    arg[count]=str1.nextToken();

    count++;
    }
      

  6.   

    不好意思我问个比较那个点的问题.........StringTokenizer是什么意思
    ----------------------我也不懂,我理解来字符表示器
      

  7.   

    String str = "The indictment said the defendants "
    + "had collected geographical data indicating "
    + "thousands of people would be killed in the "
    + "chemical blast";
    StringTokenizer st = new StringTokenizer(str," ");
    String[] arrays = new String[st.countTokens];
    for(int i = 0; i<arrays.length; i++){
       if(st.hasMoreTokens)
          arrays[i] = st.nextToken();
    }
      

  8.   

    和楼上的基本差不多 import java.util.*;
    public class Test
    {
     public static void main(String args[])
     {
      String str= "The indictment said the defendants "
                   + "had collected geographical data indicating "
                   + "thousands of people would be killed in the "
                   + "chemical blast";
      StringTokenizer str1=new StringTokenizer(str," ");    //字符解析器创建对象
      String[] StrAry=new String[str1.countTokens()];      //创建一个数组
      //输出
      while(str1.hasMoreTokens())
      {
       int i=0;
       StrAry[i]=str1.nextToken();
       System.out.println(StrAry[i]);
      }
     }
    }
    其中 StringTokenizer 是一个字符串分析器
    nextToken()方法是逐个获取下一个语言符号
    hasMoreToken()方法是只要字符串还有语言符号就返回ture
    countTokens()方法是得到字符串一共有多少个语言符号