现在有
String name = "aa;bbb;ccccc;d;eeee" ;
想把其中的aa  bbb 等等截取出来放到一个数组中, 有什么方法吗?  谢谢.!

解决方案 »

  1.   

    split()方法可以呀, 查API找到了.
      

  2.   


    用StringTokenizer类的方法去分割字符串
    但不建议把分割后的字符串放到数组中,因为数组的长度不能变,在定义时就要定义长度,不够灵活    static void getString(){
         ArrayList<String> seperate = new ArrayList<String>();
         String name = "aa;bbb;ccccc;d;eeee" ; 
         StringTokenizer st = new StringTokenizer(name,";");
         while(st.hasMoreElements()){
         seperate.add(st.nextToken());
         }
        
         System.out.println(seperate);
        }