Java String Split by Regex split(final String regex, final String value)

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

Description

split

License

Open Source License

Parameter

Parameter Description
regex a parameter
value a parameter

Declaration

public static Collection<String> split(final String regex, final String value) 

Method Source Code


//package com.java2s;

import java.util.*;

public class Main {
    /**/* w  w w  .ja  v a  2  s.  co m*/
     * @param regex
     * @param value
     * @return
     */
    public static Collection<String> split(final String regex, final String value) {
        return split(regex, value, new LinkedList<String>());
    }

    /**
     * @param <T>
     * @param regex
     * @param value
     * @param l
     * @return
     */
    public static <T extends Collection<String>> T split(final String regex, final String value, final T l) {
        final String[] bits = value.split(regex);
        for (final String bit : bits) {
            l.add(bit);
        }
        return l;
    }

    /**
     * Add objects to a collection... mostly used when an object instantiation is in the first paramter.
     */
    public static <T extends Object, C extends Collection<? super T>> C add(final C cxn, final T... objs) {
        if (objs != null) {
            for (final T obj : objs) {
                cxn.add(obj);
            }
        }
        return cxn;
    }

    public static <T extends Object, C extends Collection<? super T>> C add(final C cxn, Iterable<T> from) {
        if (from != null) {
            for (T obj : from) {
                cxn.add(obj);
            }
        }
        return cxn;
    }
}

Related

  1. split(final String string, final String regex)
  2. split(String input, String regex)
  3. split(String str, String regex)
  4. split(String str, String regex)