Home >>Java String Methods >Java String split() method
Java split() method in java string is used to splits this string against provided regular expression and returns a char array to it.
public String split(String regex) public String split(String regex, int limit)
regex - This parameter is used to applied regular expression on string.
limit - This parameter is used to limit for the number of strings in array.
It is used to return an array of strings
PatternSyntaxException if pattern for regular expression is invalid
public class SplitExample1
{
public static void main(String args[])
{
String n1="Welcome to phptpoint";
String[] words=n1.split("\\s");
for(String w:words)
{
System.out.println(w);
}
}
}
public class SplitExample1
{
public static void main(String[] args)
{
String str1 = "Phptpointtt";
String[] arr1 = str1.split("t", 0);
for (String w : arr1)
{
System.out.println(w);
}
System.out.println("Split array length: "+arr1.length);
}
}