Java String Split by Separator split(String s, char separator)

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

Description

split

License

Open Source License

Declaration

public static String[] split(String s, char separator) 

Method Source Code


//package com.java2s;
// under the terms of the GNU Lesser General Public License as published

import java.util.ArrayList;

public class Main {
    public static String[] split(String s, char separator) {
        // this is meant to be faster than String.split() when separator is not regexp
        if (s == null)
            return null;
        ArrayList<String> parts = new ArrayList<String>();
        int beginIndex = 0, endIndex;
        while ((endIndex = s.indexOf(separator, beginIndex)) >= 0) {
            parts.add(s.substring(beginIndex, endIndex));
            beginIndex = endIndex + 1;//  w w  w .j av  a  2s.  c  o  m
        }
        parts.add(s.substring(beginIndex));
        String[] a = new String[parts.size()];
        return parts.toArray(a);
    }
}

Related

  1. split(String input, int separator)
  2. split(String left, String separator)
  3. split(String s, char separator)
  4. split(String s, char separator)
  5. split(String s, char separator)
  6. split(String s, char separator)
  7. split(String s, char separator)
  8. split(String s, String separator)
  9. split(String s, String separator)