Way2Java

split() String Example

java.lang.String class comes with overloaded split() String method to split a string into tokens. Introduced in JDK 1.4, earlier done with SringTokenizerr.

The signature of split() String Example is given as defined in Java API.

In the following example, split() String Example is used to split string str1. Original string str1 is not disturbed.
public class StringMethodDemo
{
 public static void main(String args[])
 {
  String str1 = "Hello World How Do You Do";

  String sarray[] = str1.split(" ");

  System.out.println("Each word of string after splitting: ");

  for(String temp : sarray)
  {
    System.out.print(temp + ", ");
  }
 }
}



Output screenshot on split() String Example

Pass your comments and suggestion on this tutorial "split() String Example".