static private String [ ] getStringList ( String str ) { if ( str == null ) { return null ; } List < String > list = new ArrayList <> ( ) ; int i = 0 ; int length = str . length ( ) ; StringBuffer sb = null ; while ( i < length ) { char ch = str . charAt ( i ) ; if ( ch == ' ' ) { // A space was hit. Add string to list if ( sb != null ) { list . add ( sb . toString ( ) ) ; sb = null ; } } else if ( ch == ' ' ) { // It is a delimiter. Add next character if ( i + 1 < length ) { ch = str . charAt ( ++ i ) ; if ( sb == null ) { sb = new StringBuffer ( ) ; } sb . append ( ch ) ; } } else { if ( sb == null ) { sb = new StringBuffer ( ) ; } sb . append ( ch ) ; } i ++ ; // Next character } // Make sure to add the last part to the list too if ( sb != null ) { list . add ( sb . toString ( ) ) ; } if ( list . size ( ) == 0 ) { return null ; } String [ ] results = new String [ list . size ( ) ] ; return list . toArray ( results ) ; }
Converts a space delimitered string to a list of strings