Java String split() method

Java String split() method split current String against given regular expression and returns a char array.

Syntax:

Parameters:

 regex  : it is a regular expression to be applied on String.

limit : it is limit for the number of Strings in array. If it is zero , it will return all String matching regex.

Returns:

 array of Strings

Throws:

 PatternSyntaxException if pattern for regex is invalid.

Java String split() method 1 example:

Output:

Java String split() method with regex and length example 2

Output:

Java String split() method with regex and length example 3

Output:

Java String split() method with regex and limit example 4

Output:

Java String split() method example 5

Output:

Leave a Comment