Java String Split by Line Split(String line, String sptr)

Here you can find the source of Split(String line, String sptr)

Description

Split

License

BSD License

Declaration

public static List<String> Split(String line, String sptr) 

Method Source Code

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

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List<String> Split(String line, String sptr) {

        List<String> strs = null;
        if (line == null || sptr == null || line.isEmpty())
            return strs;

        strs = new ArrayList<String>();
        int pos = line.indexOf(sptr);
        if (sptr.isEmpty() || pos == -1) {
            strs.add(line);//from  w  w w .ja v  a 2  s.  c o m
            return strs;
        }

        int begin = 0;
        while (pos != -1) {
            strs.add(line.substring(begin, pos));
            begin = pos + sptr.length();
            pos = line.indexOf(sptr, begin);
        }
        strs.add(line.substring(begin));

        return strs;
    }
}

Related

  1. split(String line, String separator)
  2. split(String line, String separator)
  3. split(String line, String separator)
  4. split(String line, String separator)
  5. split(String line, String seperator)
  6. splitArguments(String commandLine, boolean backslashesAreLiteral)
  7. splitArgumentsBackslashesAreLiteral(String commandLine)
  8. splitByBrackets(String line)
  9. splitBySeparator(String line, char sep)