Split in java

This section illustrate the use of split in java. Split is used to split the string in the given format.

Split in java

This section illustrate the use of split in java. Split is used to split the string in the given format.

Split in java

Split in java

This section illustrate the use of split in java. Split is used to split the string in the given format. Java provide two methods of split and the syntax is as follows :

Syntax :

  • public String[] split (String regex, int limit)
  • public String[] split(String regex)

Here regex is the delimiting regular expression and limit in integer means how many string are returned after splitting. This method return the string after splitting it.

Example : Code to use of split method.

public class Split 
 {
  public static void main(String args[])
   {
   String st="Welcome-to-rose-india";
   String str[]=st.split("-");
    for(int i=0;i<str.length;i++)
    System.out.println(str[i]);
      }

   }

Output : After compiling and executing the above program.

Download Source Code