How to convert String to int in Java while taking care underflow and overflow int? -


i converting string int using following code:

int foo = integer.parseint("1234");
how can make sure int value not overflow or underflow?

as documentation says, if input string not contain parseable integer, numberformatexception thrown. includes inputs integers outside of range of int.

the terms "underflow" , "overflow" aren't quite terms you're looking here: refer situations have couple of integers in valid range (say, 2 billion) , add them (or perform arithmetic operation achieves similar effect) , integer outside of valid range. results in problems wrapping negatives because of two's complement , such. question, on other hand, simple case of string-encoded integers lying outside of valid range.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -