You are here:   HomeJava ProgrammingJava ArrayString split() in Java Example
by Dinesh Thakur Category: array

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





Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to contact us.



What's New and Popular





Popular Article