Java: Convert String to Integer
Question by Guest | 2016-10-01 at 09:19
Is there any possibility to change or convert a string into an integer value in Java?
I have some user inputs that are naturally only available as string. Although the string only contains or consists of digits and numbers, I cannot calculate with it. I know functions like inttostr from other programming languages, but such a function seems not to be available in Java. What can I do?
Related Topics
PHP: Check Strings with Ctype-Functions for Character Classes
Article | 0 Comments
Java: Smaller/Larger Comparison of Strings - The operator > is undefined for the argument type(s) java.lang.String
Question | 1 Answer
Android Programming: Receive Responce from HTTP POST Request
Tutorial | 0 Comments
Java: Case Insensitive Equals - String Comparison
Info | 0 Comments
Java: Split at point str.split(".") does not work
Question | 1 Answer
Android Getting Sound Levels
Open Question | 1 Answer
PHP: Convert Integer Variable to String Variable
Tutorial | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
You can use the function Integer.parseInt() for that purpose. This function returns an integer value for a given string.
For example:
Or:
However, if you want to convert user input, you should make sure that the input respectively the string really only consists of digits. For that, you can check whether the string only contains digits before the conversion or you can return a default value in doubt.
2016-10-01 at 16:11