Java String split() Method Example

There are two forms of String.split() methods.
  • split(String regex)  Splits this string around matches of the given regular expression. 
  • split(String regex, int limit)  - Splits this string around matches of the given regular expression.

Java String.split() Method Example

This is a complete example to demonstrate the usage of split()  methods.
public class SplitExample {
    public static void main(String[] args) {
        String str = "java,guides.net";
        String[] strArray = str.split(",");
        for (int i = 0;
        i <
         strArray.length;
        i++) {
            System.out.println(strArray[i]);
        }
        strArray = str.split(",", 0);
        for (int i = 0;
        i <
         strArray.length;
        i++) {
            System.out.println(strArray[i]);
        }
    }
}

Output:
java guides.net java guides.net 

Reference


Comments