Java String Split by Char split(char sep, String input)

Here you can find the source of split(char sep, String input)

Description

split

License

Open Source License

Declaration

public static List<String> split(char sep, String input) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2009, 2014 Xored Software Inc and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://w  ww .  j ava2  s.  c  o m
 *     Xored Software Inc - initial API and implementation and/or initial documentation
 *******************************************************************************/

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List<String> split(char sep, String input) {
        return split(Character.toString(sep), input);
    }

    public static List<String> split(String sep, String input) {
        List<String> result = new ArrayList<String>();
        int start = 0;
        int nextSep;
        int sepLength = sep.length();
        while ((nextSep = input.indexOf(sep, start)) != -1) {
            result.add(input.substring(start, nextSep));
            start = nextSep + sepLength;
        }
        result.add(input.substring(start));
        return result;
    }
}

Related

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