Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
29 views

Description: Syntax:: This Method Has Two Variants and Splits This String Around Matches of The Given Regular Expression

This method splits a string into an array of substrings based on a regular expression. It has two variants - one that allows specifying a limit on the number of substrings returned, and one that does not take a limit. It returns an array of strings computed by splitting the original string at matches of the given regular expression. The example demonstrates splitting a string on "-" at different limits.

Uploaded by

Vijay Kanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Description: Syntax:: This Method Has Two Variants and Splits This String Around Matches of The Given Regular Expression

This method splits a string into an array of substrings based on a regular expression. It has two variants - one that allows specifying a limit on the number of substrings returned, and one that does not take a limit. It returns an array of strings computed by splitting the original string at matches of the given regular expression. The example demonstrates splitting a string on "-" at different limits.

Uploaded by

Vijay Kanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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:

regex -- the delimiting regular expression.

limit -- the result threshold which means how many strings to be returned.

Return Value:

It returns the array of strings computed by splitting this string around matches of the given regular expression.

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 the 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

You might also like