public static String [ ] splitString ( final String str , final char splitChar ) { final int length = str . length ( ) ; final StringBuilder bulder = new StringBuilder ( Math . max ( 8 , length ) ) ; int counter = 1 ; for ( int i = 0 ; i < length ; i ++ ) { if ( str . charAt ( i ) == splitChar ) { counter ++ ; } } final String [ ] result = new String [ counter ] ; int position = 0 ; for ( int i = 0 ; i < length ; i ++ ) { final char chr = str . charAt ( i ) ; if ( chr == splitChar ) { result [ position ++ ] = bulder . toString ( ) ; bulder . setLength ( 0 ) ; } else { bulder . append ( chr ) ; } } if ( position < result . length ) { result [ position ] = bulder . toString ( ) ; } return result ; }
Split a string for a char used as the delimeter .