Home Java Beginners Split in java
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Split in java

Advertisement
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. 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

Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: May 20, 2013

Ask Questions?    Discuss: Split in java  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com