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

static ArrayList<String> split(String line, String separator) 

Method Source Code


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

import java.util.ArrayList;

public class Main {
    static ArrayList<String> split(String line, String separator) {
        ArrayList<String> items = new ArrayList<String>();

        int start, end;

        int sep_size = separator.length();

        start = 0;// w w w .  j a  v  a 2 s. c o  m
        //See: http://en.wikipedia.org/wiki/Comparison_of_programming_languages_(string_functions)
        end = line.indexOf(separator);

        while (end != -1) //See: http://en.wikipedia.org/wiki/Comparison_of_programming_languages_(string_functions) >> returns this if not found
        {
            items.add(line.substring(start, end));

            start = end + sep_size;
            end = line.indexOf(separator, start);
        }

        items.add(line.substring(start, line.length()));

        return items;
    }
}

Related

  1. split(String line)
  2. split(String line, char delimiter)
  3. split(String line, char delimiter)
  4. split(String line, String delimiter)
  5. split(String line, String regex)
  6. split(String line, String separator)
  7. split(String line, String separator)
  8. split(String line, String separator)
  9. split(String line, String seperator)