Java String Split by Char splitAt(String inputString, Character inputChar)

Here you can find the source of splitAt(String inputString, Character inputChar)

Description

split At

License

Open Source License

Declaration

public static String[] splitAt(String inputString, Character inputChar) 

Method Source Code

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

import java.util.ArrayList;

public class Main {
    public static String[] splitAt(String inputString, Character inputChar) {
        ArrayList<String> stringList = new ArrayList<String>();
        String tempString; // tempString is used to add each string into an array
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < inputString.length(); i++) {
            if (inputString.charAt(i) != inputChar) {
                sb.append(inputString.charAt(i));
            } // if
            else {
                tempString = sb.toString();
                stringList.add(tempString);
                sb.setLength(0);//from   w w  w  .  j  ava2 s  .c  om
            } // else
        } // for

        // After reaching the last character of the string, we need to do the
        // following
        tempString = sb.toString();
        stringList.add(tempString);
        sb.setLength(0);

        String[] stockArr = new String[stringList.size()];
        stockArr = stringList.toArray(stockArr);
        return stockArr;
    }
}

Related

  1. split(String string, char c)
  2. split(String string, char character)
  3. split(String toSplit, char splitChar, boolean trim)
  4. split(String val, char ch)
  5. split(String value, char splitChar)
  6. splitAt(String str, char c)
  7. splitByChar(final String message, final char ch)
  8. splitByNonNestedChars(String s, char... c)
  9. splitChars(String input, String charsToBeRemoved)