eniniz eniniz - 2 years ago 121
Java Question

how to convert String into Integer in java

I want to convert


If the String contain character it will return 0
Else it will return the number
For example the conversion of (ad12) is 0
But (12) Is 12

Answer Source

Try following:

public int getInt(String test){
            return Integer.parseInt(test.trim());
        }catch(Exception e){
            return 0;

All you need to do is use Integer class to get int value of valid integer containing string.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download