String numString = "8.35";
Integer numInt = Integer.parseInt(numString);
THIS WILL NOT WORK!!!
I made the (wrong) assumption that parseInt will just convert 8.35 to an Integer value of 8 and then do the parsing. NO! WRONG! It will throw an exception. I forgot which exactly. I will add it in later when I check. You can update blogs on dev.to, right? I hope so. Anyways, that's what I have learned. So I thought I would write this post to share my knowledge.
Top comments (2)
The exception thrown by Integer.parseInt() is NumberFormatException.
Integer.valueOf() takes both integer and string and and returns a Integer Object,While parseInt() will return primitive int and it takes only string as argument.
Thank you!