Java String Split split(String s, String splitter)

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

Description

split

License

Apache License

Declaration

public static String[] split(String s, String splitter) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static String[] split(String s, String splitter) {
        if (s == null) {
            throw new IllegalArgumentException(
                    "The string to be splitted cannot be null");
        }/*from  ww  w  . ja va  2  s .c om*/
        if (splitter == null || splitter.length() == 0) {
            throw new IllegalArgumentException(
                    "The string splitter cannot be empty");
        }
        List<String> parts = new ArrayList<>();
        int n = splitter.length();
        int i = 0;
        int j = s.indexOf(splitter);
        while (j != -1) {
            parts.add(s.substring(i, j));
            i = j + n;
            j = s.indexOf(splitter, i);
        }
        parts.add(s.substring(i));
        return parts.toArray(new String[parts.size()]);
    }
}

Related

  1. split(String s, String at)
  2. split(String s, String s1)
  3. split(String s, String seperator)
  4. split(String s, String spliter, boolean removeEmptyItem)
  5. split(String s, String splitStr)
  6. split(String self)
  7. split(String signature, boolean skipInitialAngleBracket)
  8. split(String source, String seperator)
  9. split(String str)