split
public String[] split(String regex)
Splits this string around matches of the given regular expression. 
This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array. The string "boo:and:foo", for example, yields the following results with these expressions: Regex     Result 
: { "boo", "and", "foo" } 
o { "b", "", ":and:f" } 
Parameters:
regex - the delimiting regular expression 
Returns:
the array of strings computed by splitting this string around matches of the given regular expression 
Throws: 
PatternSyntaxException - if the regular expression's syntax is invalid 
NullPointerException - if regex is null
Since: 
1.4 
See Also:
Pattern

解决方案 »

  1.   


    String s="aaa,bbb,ccc,ddd,eee,fff";
    String[] arg=s.split(",");注:jdk1.4 才有此方法祝你好运!
      

  2.   


    import java.util.*;
    public class Test9 {
      public Test9() {
      }
      public static void main(String[] args) {
        Test9 test91 = new Test9();
        String line = "aaa,bbb,ccc,ddd,eee,fff";
        String[] a=new String[100];
        StringTokenizer dataArr = new StringTokenizer(line, ",");
        while(dataArr.hasMoreElements()){
          a[1]=(String)dataArr.nextElement();
        }  }}
      

  3.   

    大概我写错了,我 的意思是说
    如果一个string型的变量为"aaa;bbb,ccc,ddd;eee,fff"怎么样把数据放入数组
    使 得a[0]=aaa,a[1]=bbb,a[2]=ccc,a[3]=ddd........?高手请进
    就是说,即有分号,又有逗号,怎么样来使数据放入组啊
      

  4.   

    如果知道长度的话可以用 substring方法
    string s="aaa;bbb,ccc,ddd;eee,fff";
    string a=s.substring[0,3];
      

  5.   

    先把分号转换成逗号。再用split(",")啊
      

  6.   

    先replaceAll然后再split就可以了
      

  7.   

    String s="aaa;bbb,ccc,ddd;eee,fff";
    s = s.replaceAll(";",",");
    String[] str = s.split(",");
    ---------
    string s="aaa;bbb,ccc,ddd;eee,fff";
    String a[] = new String[dataArr.countTokens()];
    StringTokenizer dataArr = new StringTokenizer(s,",;");
    int i = 0 ;
    while(dataArr.hasMoreElements()){
       a[i]=(String)dataArr.nextElement();
       i++;
    }
      

  8.   

    import java.util.*;
    public class Test9 {
      public Test9() {
      }
      public static void main(String[] args) {
        Test9 test91 = new Test9();
        String line = "aaa,bbb,ccc;ddd,eee,fff";
        String[] a=new String[100];
        StringTokenizer dataArr = new StringTokenizer(line, ";,");
        int s=0;
        while(dataArr.hasMoreElements()){
          a[s++]=(String)dataArr.nextElement();
        }
        for(int i=0;i<100;i++){
          System.out.println(a[i]);
        }  }}