close
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";
全站熱搜