public static String [ ] getTokens ( String str , String delim , boolean trim ) { StringTokenizer stok = new StringTokenizer ( str , delim ) ; String tokens [ ] = new String [ stok . countTokens ( ) ] ; for ( int i = 0 ; i < tokens . length ; i ++ ) { tokens [ i ] = stok . nextToken ( ) ; if ( trim ) tokens [ i ] = tokens [ i ] . trim ( ) ; } return tokens ; }
Splits given string into tokens with delimiters specified . It uses StringTokenizer for tokenizing .