14 May String split(String regex, int limit) method in Java
The split(String regex, int limit) method in Java splits this string around matches of the given regular expression.
Syntax
Let us see the syntax,
1 2 3 |
String[] split(String regex, int limit) |
Parameters
Let us see the parameters,
- regex − delimiting regular expression
- limit − the result threshold, the limit of the strings to be returned
Example
The following is an example of String[] split(String regex, int limit),
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
public class StudyopediaDemo { public static void main(String args[]) { String message = new String("Studyopedia-provides-free-learning content!"); System.out.println("String: "+message); System.out.println("After split:"); for (String result: message.split("-",4)) { System.out.println(result); } } } |
Output
The following is the output,
No Comments