private static List < String > splitStringByDelimeters ( String str , char [ ] delimeter , boolean includeDeli ) { List < String > arr = new ArrayList < String > ( ) ; int i = 0 , start = 0 , quota = 0 ; char pre = 0 ; for ( char c : str . toCharArray ( ) ) { if ( c == ' ' && pre != ' ' ) { quota ++ ; } if ( quota % 2 == 0 ) { for ( char deli : delimeter ) { if ( c == deli ) { if ( includeDeli ) { arr . add ( str . substring ( start , i ) . trim ( ) ) ; start = i ; } else if ( i > start ) { arr . add ( str . substring ( start , i ) . trim ( ) ) ; start = i + 1 ; } } } } i ++ ; pre = c ; } if ( includeDeli ) { arr . add ( str . substring ( start , i ) . trim ( ) ) ; start = i ; } else if ( i > start ) { arr . add ( str . substring ( start , i ) . trim ( ) ) ; } return arr ; }
Split a complete String to String array by the delimeter array .