public static String[] split(final CharSequence charSequence,final char separator){
  if (isEmpty(charSequence)) {
    return EMPTY_ARRAY;
  }
  final int originalSeparatorsCount=countSeparatedCharAppearances(charSequence,separator);
  int separatorsCount=originalSeparatorsCount;
  if (startsWith(charSequence,separator)) {
    separatorsCount--;
  }
  if (charSequence.length() > 1 && endsWith(charSequence,separator)) {
    separatorsCount--;
  }
  if (separatorsCount <= 0) {
    if (originalSeparatorsCount == 0) {
      return new String[]{charSequence.toString()};
    }
 else     if (isSameChar(charSequence)) {
      return EMPTY_ARRAY;
    }
    return new String[]{removeCharacter(charSequence.toString(),separator)};
  }
  final String[] result=new String[separatorsCount + 1];
  int currentResultIndex=0;
  final StringBuilder builder=new StringBuilder();
  for (int index=0, length=charSequence.length(); index < length; index++) {
    final char character=charSequence.charAt(index);
    if (character == separator) {
      if (isNotEmpty(builder)) {
        result[currentResultIndex++]=builder.toString();
        clearBuilder(builder);
      }
    }
 else {
      builder.append(character);
    }
  }
  if (isNotEmpty(builder)) {
    result[currentResultIndex++]=builder.toString();
  }
  return result;
}

public static String [ ] split ( final CharSequence charSequence , final char separator ) { if ( isEmpty ( charSequence ) ) { return EMPTY_ARRAY ; } final int originalSeparatorsCount = countSeparatedCharAppearances ( charSequence , separator ) ; int separatorsCount = originalSeparatorsCount ; if ( startsWith ( charSequence , separator ) ) { separatorsCount -- ; } if ( charSequence . length ( ) > 1 && endsWith ( charSequence , separator ) ) { separatorsCount -- ; } if ( separatorsCount <= 0 ) { if ( originalSeparatorsCount == 0 ) { return new String [ ] { charSequence . toString ( ) } ; } else if ( isSameChar ( charSequence ) ) { return EMPTY_ARRAY ; } return new String [ ] { removeCharacter ( charSequence . toString ( ) , separator ) } ; } final String [ ] result = new String [ separatorsCount + 1 ] ; int currentResultIndex = 0 ; final StringBuilder builder = new StringBuilder ( ) ; for ( int index = 0 , length = charSequence . length ( ) ; index < length ; index ++ ) { final char character = charSequence . charAt ( index ) ; if ( character == separator ) { if ( isNotEmpty ( builder ) ) { result [ currentResultIndex ++ ] = builder . toString ( ) ; clearBuilder ( builder ) ; } } else { builder . append ( character ) ; } } if ( isNotEmpty ( builder ) ) { result [ currentResultIndex ++ ] = builder . toString ( ) ; } return result ; }
as opposed to string ' s split , this method allows to split a char sequence without a regex , provided that the separator is a single character . since it does not require pattern compiling and is a simple iteration , this method should be always preferred when it can be used .
