java中的split方法中参数作用

split 方法
将一个字符串分割为子字符串,然后将结果作为字符串数组返回。

stringObj.split([separator,[limit]])

limit
可选项。该值用来限制返回数组中的元素个数。

示例:
public class SplitDemo {

     public static String[] ss = new String[20];

     public SplitDemo() {

         String s = "The rain in Spain falls mainly in the plain.";
         // 在每个空格字符处进行分解。
         ss = s.split(" ", 2);
     }

     public static void main(String[] args) {
         SplitDemo demo = new SplitDemo();
         for (int i = 0; i < ss.length; i++)
             System.out.println(ss[i]);
     }

}

程序结果:
The
rain in Spain falls mainly in the plain.

posted on 2021-05-26 09:39  jped  阅读(680)  评论(0编辑  收藏  举报