Converting String to Int with value validation
Hi. I'm new to java. I just wanted to know how do I
- Convert String to Int. Also, I would like the conversion to produce and error if the data type is wrongly assign
- Also, I would like the conversion to produce an error if the data type is wrongly assign. (Example: Assigning 'A' into integer, will be a disaster)
So, how do i overcome this problem? Thank you.
Re: Converting String to Int with value validation
Hi and welcome to the forum ncode
Quote:
Convert String to Int. Also, I would like the conversion to produce and error if the data type is wrongly assign
Your favorite search engine is the better place for a question so vague. The only way to answer that here is to break out a full lesson on the subject, or just post working code.
Quote:
Also, I would like the conversion to produce an error if the data type is wrongly assign.
Didn't you just say that on the line above too?
Do some research and post a question when you get stuck. Don't forget to include your code (in tags) and error messages.
Re: Converting String to Int with value validation
there is an Integer class called in java a wrapper class that converts a valid numerical String into a process-able integer number
Integer (Java 2 Platform SE v1.4.2)
you dont need to worry about monitoring if the String being parsed is valid/invalid, this class will throw you an exception if you attempt passing an invalid String number
Re: Converting String to Int with value validation
Thx for reply. Ya. This question is a bit of vague. But anyway, chronoz13 provided me some guide. Thank you.