public static String [ ] split ( String str , char separator ) { // String.split returns a single empty result for splitting the empty // string. if ( str . isEmpty ( ) ) { return new String [ ] { "" } ; } ArrayList < String > strList = new ArrayList < String > ( ) ; int startIndex = 0 ; int nextIndex = 0 ; while ( ( nextIndex = str . indexOf ( separator , startIndex ) ) != - 1 ) { strList . add ( str . substring ( startIndex , nextIndex ) ) ; startIndex = nextIndex + 1 ; } strList . add ( str . substring ( startIndex ) ) ; // remove trailing empty split(s) int last = strList . size ( ) ; // last split while ( -- last >= 0 && "" . equals ( strList . get ( last ) ) ) { strList . remove ( last ) ; } return strList . toArray ( new String [ strList . size ( ) ] ) ; }
Split a string using the given separator with no escaping performed .