by Dinesh Thakur

String [] split (String regex):This method splits the invoking string into substrings at each match for a specified regular expression regex and returns a reference to an array of substrings. For example, consider the statements.

String str = "Hello Java";

String[] s = str.split("[]");

The first statement defines the string to be analyzed. The second statement calls the split () method for the str object to decompose the string. The regular expression includes the delimiterspace so it will return a reference to array of strings where s[0] contains Welcome, s[1] contains toand s[2] contains Java.

public class StringSplit

{
     public static void main(String[] args)
     {
            String str3 = "Where there is a Will , there is a way";
            String str[] = str3.split(" ");
                 for(int i=0;i<str.length;i++)
                      System.out.println("str[" + i + "]  : " + str[i]);
      }
}

String split() in Java Example