Java String Split by Delimiter splitString(String source, String delimiter)

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

Description

split String

License

Open Source License

Declaration

public static String[] splitString(String source, String delimiter) 

Method Source Code

//package com.java2s;
/**/*from   w  w w.j  a va2 s .  c o m*/
 *    Copyright Masao Nagasaki
 *    Nagasaki Lab
 *    Laboratory of Biomedical Information Analysis,
 *    Department of Integrative Genomics,
 *    Tohoku Medical Megabank Organization, Tohoku University 
 *    @since 2013
 *
 *    This file is part of SUGAR (Subtile-based GUI-Assisted Refiner).
 *    SUGAR is an extension of FastQC (copyright 2010-12 Simon Andrews)
 *
 *    SUGAR 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; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    SUGAR 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 SUGAR; if not, write to the Free Software
 *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static String[] splitString(String source, String delimiter) {
        List<String> list = new ArrayList<String>();
        int idx = 0;
        while ((idx = source.indexOf(delimiter)) >= 0) {
            list.add(source.substring(0, idx));
            source = source.substring(idx + 1);
        }
        if (source != null && !source.isEmpty()) {
            list.add(source);
        }
        return list.toArray(new String[list.size()]);
    }
}

Related

  1. splitStr(String str, char delimiter, boolean trim)
  2. splitString(CharSequence s, char delim)
  3. splitString(final String values, final char delimiter)
  4. splitString(String data, String delimiter)
  5. splitString(String originalString, String delimeter)
  6. splitString(String splitStr, String delim)
  7. splitString(String str, char delim)
  8. splitString(String str, String delim)
  9. splitString(String str, String delimiter)