This splits the string approximately competitions of the known normal expression. The collection revisited by this technique encloses each substring of this string that is terminated by another substring. The matches the agreed look or is terminated by the end of the string.
Here is the syntax of this method:
public String[] split(String regex, int limit)
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("-", 2)) { System.out.println(retval); } System.out.println(""); System.out.println("Return Value :" ); for (String retval: Str.split("-", 3)) { System.out.println(retval); } System.out.println(""); System.out.println("Return Value :" ); for (String retval: Str.split("-", 0)) { System.out.println(retval); } System.out.println(""); } }
This will produce the following result:
Return Value : Welcome to-Intellinuts.com Return Value : Welcome to Intellinuts.com Return Value: Welcome to Intellinuts.com
Here at Intellinuts, we have created a complete Java tutorial for Beginners to get started in Java.