Java String Split by Char split(String s, char c)

Here you can find the source of split(String s, char c)

Description

split

License

Open Source License

Declaration

public static List<String> split(String s, char c) 

Method Source Code

//package com.java2s;
/*/* w w  w .jav  a2s .c o  m*/
 * 
 * Copyright 2012 lexergen.
 * This file is part of lexergen.
 * 
 * lexergen 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.
 * 
 * lexergen 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 lexergen.  If not, see <http://www.gnu.org/licenses/>.
 *  
 * lexergen:
 * A tool to chunk source code into tokens for further processing in a compiler chain.
 * 
 * Projectgroup: bi, bii
 * 
 * Authors: Johannes Dahlke
 * 
 * Module:  Softwareprojekt ?bersetzerbau 2012 
 * 
 * Created: Apr. 2012 
 * Version: 1.0
 *
 */

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List<String> split(String s, char c) {
        int beginIndex = 0;
        int endIndex;
        ArrayList<String> findings = new ArrayList<String>();
        while ((endIndex = s.indexOf(c, beginIndex)) > -1) {
            findings.add(s.substring(beginIndex, endIndex));
            beginIndex = endIndex + 1;
        }
        if (s.length() > 0)
            findings.add(s.substring(beginIndex, s.length()));
        return findings;
    }
}

Related

  1. split(char elem, String orig)
  2. split(char sep, String input)
  3. split(final String input, final char split)
  4. split(final String string, final char... toSplit)
  5. split(String cs, char sep)
  6. split(String s, char c)
  7. split(String s, char c)
  8. split(String s, char c, int limit)
  9. split(String s, char c, int limit)