Java Basics
Java Object Oriented
Java Advanced
Java Useful References
Java Useful Resources
Selected Reading
© 2011 TutorialsPoint.COM
|
Java - String split() Method
Description:
This method has two variants and splits this string around matches of the given regular expression.
Syntax:
Here is the syntax of this method:
public String[] split(String regex, int limit)
or
public String[] split(String regex)
|
Parameters:
Here is the detail of parameters:
Return Value :
Example:
import java.io.*;
public class Test{
public static void main(String args[]){
String Str = new String("Welcome-to-Tutorialspoint.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("");
System.out.println("Return Value :" );
for (String retval: Str.split("-")){
System.out.println(retval);
}
}
}
|
This produces following result:
Return Value :
Welcome
to-Tutorialspoint.com
Return Value :
Welcome
to
Tutorialspoint.com
Return Value:
Welcome
to
Tutorialspoint.com
Return Value :
Welcome
to
Tutorialspoint.com
|
|
|
|