Java String Explode explode(String s, String delim)

Here you can find the source of explode(String s, String delim)

Description

Split a string on delimiter boundaries, and place each element into a List.

License

Open Source License

Parameter

Parameter Description
s String to split up
delim Delimiting token, ala StringTokenizer

Return

a List comprised of elements split by the tokenizing

Declaration

public static List<String> explode(String s, String delim) 

Method Source Code

//package com.java2s;
/*// ww  w .  j a va2  s  .  co  m
 * RHQ Management Platform
 * Copyright 2010-2011, Red Hat Middleware LLC, and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**
     * Split a string on delimiter boundaries, and place each element into a List.
     *
     * @param  s     String to split up
     * @param  delim Delimiting token, ala StringTokenizer
     *
     * @return a List comprised of elements split by the tokenizing
     */
    public static List<String> explode(String s, String delim) {
        List<String> res = new ArrayList<String>();
        if (s == null)
            return res;

        String[] tokens = s.split(delim);
        for (String token : tokens) {
            res.add(token);
        }

        return res;
    }
}

Related

  1. explode(String csv)
  2. explode(String data, String delim)
  3. explode(String delim, String string)
  4. explode(String handleStr, String pointStr)
  5. explode(String input, final char delimiter, final char escape, final int capacity)
  6. explode(String source, String deliminator)
  7. explode(String split, String input)
  8. explode(String src, String sep)
  9. explode(String string, String separators)