Java String Split by Line split(String line, String separator)

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

Description

split

License

Open Source License

Declaration

public static String[] split(String line, String separator) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    public static String[] split(String line, String separator) {
        assertNotNull("line", line);
        assertNotNull("separator", separator);
        //if(separator.length() == 0)
        //    throw new new("separator", separator, "May not be empty");
        if (line.length() == 0)
            return new String[0];
        int separatorLength = separator.length();
        List list = new ArrayList();
        int previousIndex = 0;
        for (int index = line.indexOf(separator); index != -1; index = line.indexOf(separator, previousIndex)) {
            list.add(line.substring(previousIndex, index));
            previousIndex = index + separatorLength;
        }//  w w w  .j  ava 2 s . com

        list.add(line.substring(previousIndex));
        String stringArray[] = new String[list.size()];
        list.toArray(stringArray);
        return stringArray;
    }

    private static void assertNotNull(String fieldName, Object object) {
        //if(object == null)
        //    throw new DetailedNullPointerException(fieldName);
        //else
        return;
    }
}

Related

  1. split(String line, char delimiter)
  2. split(String line, String delimiter)
  3. split(String line, String regex)
  4. split(String line, String separator)
  5. split(String line, String separator)
  6. split(String line, String separator)
  7. split(String line, String seperator)
  8. Split(String line, String sptr)
  9. splitArguments(String commandLine, boolean backslashesAreLiteral)