string不是有个getbytes可以返回的吗?

解决方案 »

  1.   

    在jdk1.4下有split这个函数
    在1。3下只好自己写了,一个例子
    public static String[] split(String inStr)
        {
          String[] rtValue = null;
          Hashtable h = new Hashtable();
          Enumeration e;
          int i;
          int b = 0;
          int l=0;      while((i = inStr.indexOf(",", b)) != -1)
          {
            h.put(inStr.substring(b, i), "");
            l++;
            b = i+1;
          }
          if(b < inStr.length())
          {
            h.put(inStr.substring(b, inStr.length()), "");
          }      rtValue = new String[h.size()];
          e = h.keys();
          i=0;
          while(e.hasMoreElements())
          {
            rtValue[i] = (String)e.nextElement();
            i++;
            //rtValue[] = ;
          }      return rtValue;
        }
      

  2.   

    String s ="aaa@bbb@ccc@ddd@ee";
    String[] result = s.split("@");
    result就是你要的数组(这个split方法是jdk1.4的,1.3的你要用StringTokenizer)函数的话://主要步骤是下面两步,其它的不全的自己写吧
    public String[] ssss(String source,String split)
    {
      String[] result = source.split(split);
      return result; 
    }
      

  3.   

    public static String[] split(String s, String separator)
    {
        if(s == null)
            throw new NullPointerException("source String cannot be null");
        if(separator == null)
            throw new NullPointerException("separator cannot be null");
        if(separator.length() == 0)
            throw new IllegalArgumentException("separator cannot be empty");    ArrayList buffer = new ArrayList();
        
        int start = 0;
        int end = s.indexOf(separator);
        while(end != -1)
        {
            buffer.add(s.substring(start, end));
            start = end + separator.length();
            end = s.indexOf(separator, start);
        }
        buffer.add(s.substring(start, s.length()));    return (String[]) buffer.toArray(new String[0]);
    }example:String[] result = split("abc,123,a,b,x", ",");
      

  4.   

    char[] stringToArray(String input){
      char[] output=new char[input.length()];
      for(int i=0;i<input.length();i++){
        output[i]=input.charAt(i);
      }
      return output
    }
      

  5.   

    我想你是要这个吧
    import java.util.ArrayList;
    import java.util.List;
    import java.util.StringTokenizer;public class Mtest { public static void main(String[] args) {
            String aaa = "aaa,bbb,ccc,ddd,eee";
            String[] aa = change(aaa, ",");
            for (int i = 0; i < aa.length; i++) {
                System.out.println(aa[i]);
            }
    }
        
        public static String[] change(String str1, String str2) {
            StringTokenizer temp = new StringTokenizer(str1, str2);
            List list = new ArrayList();
            while (temp.hasMoreTokens()) {
                list.add(temp.nextToken());        
            }
            return (String[]) list.toArray(new String[0]);
        }}
      

  6.   

    看看jdk中的\demo\applets\GraphLayout.java里面有现成的把字符串解析成数组的方法。
      

  7.   

    class testArray
    {
    public static void main(String args[])
    {
    String str = new String("a,b,c,d,e");
    try
    {
    String[] strArrayList= str.split(",");
    for(int i=0;i<strArrayList.length;i++)
    {
    System.out.println(strArrayList[i]);
    }
    }
    catch(Exception ex)
    {
    ex.printStackTrace();
    }
    }
    }
    要求jdk1.4