public static List < String > splitStringCommaSpace ( String line ) { List < String > words = new ArrayList <> ( ) ; int len = line . length ( ) ; int pos = 0 ; while ( pos < len ) { // Skip past blank space char ch ; while ( pos < len && ( ( ch = line . charAt ( pos ) ) <= ' ' || ch == ' ' ) ) pos ++ ; int start = pos ; // Skip to the next blank space while ( pos < len && ( ch = line . charAt ( pos ) ) > ' ' && ch != ' ' ) pos ++ ; if ( pos > start ) words . add ( line . substring ( start , pos ) ) ; } return words ; }
Splits a string into multiple words on either whitespace or commas