Java String Split by Delimiter split(String str, String delimiter)

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

Description

split

License

Open Source License

Declaration

public static String[] split(String str, String delimiter) 

Method Source Code

//package com.java2s;
/*(C) 2007-2012 Alibaba Group Holding Limited.   
 *This program is free software; you can redistribute it and/or modify   
*it under the terms of the GNU General Public License version 2 as   
* published by the Free Software Foundation.   
* Authors:   // w  w w.ja va2 s.c  o m
*   junyu <junyu@taobao.com> , shenxun <shenxun@taobao.com>,   
*   linxuan <linxuan@taobao.com> ,qihao <qihao@taobao.com>    
*/

import java.util.ArrayList;

public class Main {
    public static String[] split(String str, String delimiter) {
        String[] strs = str.split(delimiter);
        ArrayList<String> list = new ArrayList<String>(strs.length);

        for (String s : strs) {
            if (s != null && (s = s.trim()).length() > 0) {
                list.add(s);
            }
        }
        return list.toArray(new String[0]);
    }

    public static String trim(String str) {
        if (str != null) {
            return str.trim();
        }
        return null;
    }
}

Related

  1. split(String str, String delimeter)
  2. split(String str, String delimiter)
  3. split(String str, String delimiter)
  4. split(String str, String delimiter)
  5. split(String str, String delimiter)
  6. split(String str, String delimiter, int limit)
  7. split(String str, String delims)
  8. split(String str, String regexDelim, int limitUseRegex)
  9. split(String string, String delim, boolean doTrim)