Java String Split by Line splitter(String line, char delimeter)

Here you can find the source of splitter(String line, char delimeter)

Description

splitter

License

Open Source License

Declaration

public static String[] splitter(String line, char delimeter) 

Method Source Code


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

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static String[] splitter(String line, char delimeter) {
        List<String> strs = new ArrayList<>();
        int idxOfNextWord = 0;
        for (int i = 0; i < line.length(); i++) {
            if (line.charAt(i) == delimeter) {
                strs.add(line.substring(idxOfNextWord, i));
                idxOfNextWord = i + 1;//  w w w.  j av a 2 s.  c o m
            }

            if (i == line.length() - 1 && line.charAt(i) == delimeter) {
                strs.add("");
            }
        }
        return strs.toArray(new String[0]);
    }
}

Related

  1. splitMultiline(String text, boolean trimLines)
  2. splitNewLines(final String input)
  3. splitNextWord(String line)
  4. splitString(String line)
  5. splitStringPerWord(String string, int wordsPerLine)
  6. splitToLines(CharSequence str)
  7. splitToLines(final String str)
  8. splitToPairs(String Line)
  9. stringSplit(String line, String delimiter)