Java String split(String regex) Example
String class split(String regex) method example
String class split(String regex) method example. This example shows you how to use split(String regex) method.This method Splits this string around matches of the given regular expression.
Syntax:-split(String regex, int limit)
Here is the code:-
/*
* @(#) Splitstring1.java
*Program Shows a class Splitting string around matches of the given regular expression.
* @Version 01-May-2008
* @author Rose India Team
*/
import java.util.regex.Pattern;
class Splitstring1
{
private static String REGEX = "=";
private static String INPUT = "Welcome=to=Rose=India=.net";
public static void main(String[] argv) {
/*A compiled representation of a regular expression.
regular expression, specified as a string, must first be compiled into an instance of this class.*/
Pattern p = Pattern.compile(REGEX);
// editing your input file, regex.txt
String[] items = p.split(INPUT,3);
for (int i = 0; i < items.length; i++) {
System.out.println(items[i]);
}
}
} |
null
|