We know that we can split the string by the method , split(String regex);

Besides , there is a another overloading function , split(String regex , int limit) , to achieve this purpose.

If the limit n is greater than zero then the pattern will be applied at most n - 1 times.

for example : 

 

String str = "abc bcd cde def";

String[] strSplit = str.split(" " , 2);

then the str will be split to "abc" , "bcd cde def";

if we set the limit equal to 3 , that is:

String[] strSplit = str.split(" " , 3);

then the str will be split to "abc" , "bcd" ,"cde def";

文章標籤
全站熱搜
創作者介紹
創作者 JerryCheng 的頭像
JerryCheng

KwCheng's blog

JerryCheng 發表在 痞客邦 留言(0) 人氣(153)