Sunday 3 March 2019

String split(String regex, int limit) Method

String split(String regex, int limit) 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)

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("");
   }
}
This will produce the following result −

Output

Return Value :
Welcome
to-Tutorialspoint.com

Return Value :
Welcome
to
Tutorialspoint.com

Return Value:
Welcome
to
Tutorialspoint.com

No comments:

Post a Comment

Unity Top Download

Latest post

An Introduction to Hybris from basics

An Introduction to Hybris from basics:  -- ecommerce site and PCM(Product content Management) solutions. eg. croma website.  -- having sear...

Popular posts