Brandon_J
14
Q:

conversion of string to integer in java

String myString = "1234";
int foo = Integer.parseInt(myString);
19
int i = Integer.parseInt(myString);
7
There are two methods available in java to convert string to integer.
One is
Integer.parseInt() method and another one is
Integer.valueOf() method. Both these methods are static methods
of java.lang.Integer class. Both these methods throw
NumberFormatException if input string is not a valid integer.
1
String example = "1";
int converted = Integer.parseInt(example);
1
class Scratch{
    public static void main(String[] args){
        String str = "50";
        System.out.println( Integer.parseInt( str ));   // Integer.parseInt()
    }
}
5
Integer.parseInt(str);
3
class scratch{
    public static void main(String[] args) {
        String str = "54";
        int num = Integer.parseInt("54");
        double doub = Double.parseDouble("54");
    }
}
0

New to Communities?

Join the community