Pattern: split(String str) : Pattern « java.util.regex « Java by API






Pattern: split(String str)

/*
 * Output:
Next token: www
Next token: java2s
Next token: com
Next token: java
Next token: javascript
Next token: API
Next token: example
 * */

import java.util.regex.Pattern;

public class MainClass {
  public static void main(String args[]) {

    Pattern pat = Pattern.compile("[ ,.!]");

    String strs[] = pat.split("www.java2s.com java javascript API example.");

    for (int i = 0; i < strs.length; i++)
      System.out.println("Next token: " + strs[i]);

  }
}

           
       








Related examples in the same category

1.Pattern.CANON_EQ
2.Pattern.CASE_INSENSITIVE
3.Pattern: compile('d.*ian')
4.Pattern: compile('(\\w+)\\s(\\d+)')
5.Pattern: compile('e.+?d')
6.Pattern: compile('[a-z]+')
7.Pattern: compile(String text)
8.Pattern: matcher(String text)