public static int [ ] parseDestinationsString ( String s ) { if ( ! s . contains ( "," ) ) { return new int [ ] { Integer . valueOf ( s . trim ( ) ) } ; } String [ ] array = s . split ( "," ) ; int [ ] destinations = new int [ array . length ] ; for ( int i = 0 ; i < destinations . length ; i ++ ) { final String stringWithNoWhiteSpaces = array [ i ] . replaceAll ( "\\s" , "" ) ; if ( stringWithNoWhiteSpaces . isEmpty ( ) ) { throw new IllegalArgumentException ( "Empty destination. Too many commas?" ) ; } destinations [ i ] = Integer . valueOf ( stringWithNoWhiteSpaces ) ; } return destinations ; }
Returns an array of destination ids from a comma - separated list of destinations .