private static Integer toInteger ( String str ) { char [ ] chars = str . toCharArray ( ) ; int result = 0 ; int multiplier = 1 ; for ( int i = chars . length - 1 ; i >= 0 ; -- i , multiplier *= 10 ) { char c = chars [ i ] ; if ( ' ' <= c && c <= ' ' ) { result += ( c - ' ' ) * multiplier ; } else { return null ; } } return result ; }
A very simplistic conversion of string to positive integer in only decimal radix .