This way has two alternatives and splits this thread around matches of the known normal expression. The method split() splits a String into numerous Strings given the delimiter that separates them. The returned item is an array that surrounds the split Strings. We can also overtake a limit to the number of elements in the returned array.
Here is the syntax of this method:
public String[] split(String regex)
Here is the detail of parameters −
import java.io.*; public class Test { public static void main(String args[]) { String Str = new String("Welcome-to-intellinuts.com"); System.out.println("Return Value :" ); for (String retval: Str.split("-")) { System.out.println(retval); } } }
This will produce the following result:
Return Value : Welcome to intellinuts.com
Here at Intellinuts, we have created a complete Java tutorial for Beginners to get started in Java.