String[] split(String regex) 
          Splits this string around matches of the given regular expression. 
 String[] split(String regex, int limit) 
          Splits this string around matches of the given regular expression. 

解决方案 »

  1.   

    import java.util.StringTokenizer;
    .........StringTokenizer stTemp = new StringTokenizer("this is a string"," ");//" "是空格
    String[] b = new String[5];
    int      mIntCount = 0;
    while(stTemp.hasMoreTokens())
    {
      try
      {
        b[mIntCount] = stTemp.nextToken();
        System.out.println(b[mIntCount]);
        mIntCount++;
      }
      catch(Exception e1)
      {
     
      }
    }
      

  2.   

    可以用Vectorimport java.util.StringTokenizer;
    .........StringTokenizer stTemp = new StringTokenizer("this is a string"," ");//" "是空格
    Vector b = new Vector();while(stTemp.hasMoreTokens())
    {
      try
      {
        String temp = stTemp.nextToken();
        System.out.println(temp);
        b.addElement(temp);
      }
      catch(Exception e1)
      {
     
      }
    }
      

  3.   

    还是StringTokenizer效率最高,不用寻求那么多答案,选最优的吧
      

  4.   

    public String[] stringSplit(String sourceString, String spliter)
      {
        String S1 = sourceString;
        String S2 = spliter;
        if(S1==null||S2==null||S1.equals("")||S2.equals(""))
        {
          return null;
        }
        else if(S1.length() <= S2.length())
        {
          if(S1.equals(S2))
          {
            return null;
          }
          else
          {
            String[] newArray = new String[1];
            newArray[0] = S1;
            return newArray;
          }
        }
        else
        {
          String temp_String1 = "";
          String temp_String2 = "";
          //ArrayList array = new ArrayList();
          Vector array = new Vector();
          int length = S2.length();
          int max = 0;
          for(int i=0; i<S1.length(); i++)
          {
            max = (i + length >= S1.length()? S1.length():i + length);
            temp_String1 = S1.substring(i, max);
            if(temp_String1.equals(S2))
            {
              if(!temp_String2.equals(""))
              {
    //            array.add(temp_String2);
                array.addElement(temp_String2);
                temp_String2 = "";
              }
              i += length - 1;
            }
            else
            {
              if(max!=S1.length())
              {
                temp_String2 += temp_String1.substring(0,1);
              }
              else
              {
                temp_String2 += temp_String1;
    //          array.add(temp_String2);
                array.addElement(temp_String2);
                i += length;
                temp_String2="";
              }
             }
          }
          String[] returnArray = new String[array.size()];
    /*    for(int i=0; i<array.size(); i++)
          {
            returnArray[i] = (String)array.get(i);
          }
    */
          array.copyInto(returnArray);
          return returnArray;
        }
      }
      

  5.   

    效率太低,不如dylanwolf()的StringTokenizer方案