Java String Split split(String str, String splitter)

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

Description

Split a string into pieces based on delimiters.

License

Apache License

Parameter

Parameter Description
str Full string
splitter Characters to split on

Return

List of String pieces from full string

Declaration

public static List<String> split(String str, String splitter) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {
    /**/*w ww .j  a va  2 s.  c  o  m*/
     * Split a string into pieces based on delimiters.  Similar to the perl function of
     * the same name.  The delimiters are not included in the returned strings.
     * @see #join
     *
     * @param str Full string
     * @param splitter Characters to split on
     * @return List of String pieces from full string
     */
    public static List<String> split(String str, String splitter) {
        StringTokenizer tokens = new StringTokenizer(str, splitter);
        ArrayList<String> l = new ArrayList<String>(tokens.countTokens());
        while (tokens.hasMoreTokens()) {
            l.add(tokens.nextToken());
        }
        return l;
    }
}

Related

  1. split(String str)
  2. split(String str)
  3. split(String str, int ch)
  4. split(String str, String id)
  5. split(String str, String splitStr)
  6. split(String str, String token)
  7. split(String string)
  8. split(String string)
  9. split(String string, String seperator)