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.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM