Java String Split by Regex split(String str, String regex)

Here you can find the source of split(String str, String regex)

Description

Splits the given string using the given regex as delimiters.

License

Open Source License

Parameter

Parameter Description
str String to split up
regex String to compile as the regular expression

Return

List of Strings resulting from splitting on the regex

Declaration

public static List split(String str, String regex) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Arrays;

import java.util.List;

public class Main {
    /**//from ww w . j a  v  a 2s  .c  o m
     * Splits on whitespace (\\s+).
     */
    public static List split(String s) {
        return (split(s, "\\s+"));
    }

    /**
     * Splits the given string using the given regex as delimiters. This method
     * is the same as the String.split() method (except it throws the results in
     * a List), and is included just to give a call that is parallel to the
     * other static regex methods in this class.
     *
     * @param str
     *            String to split up
     * @param regex
     *            String to compile as the regular expression
     * @return List of Strings resulting from splitting on the regex
     */
    public static List split(String str, String regex) {
        return (Arrays.asList(str.split(regex)));
    }
}

Related

  1. split(final String regex, final String value)
  2. split(final String string, final String regex)
  3. split(String input, String regex)
  4. split(String str, String regex)
  5. split(String string, String pattern)
  6. split(String text, String pattern)
  7. splitAndTrim(String s, String regex)
  8. splitList(String list, String splitRegex)