-2

How can I convert a String to an int in Java?

My String contains only numbers and I want to return the number it represents.

For example, given the string "1234" the result should be the number 1234

 String Availability = json.getString("Availability");before parsing value ="4" 
 int x = Integer.parseInt(Availability);here after parsing it gives me 2 i don't know why 
hashim
  • 69
  • 1
  • 14

1 Answers1

0

You can use the foll function Integer.valueOf here is an example

public static void main(String args[]){
    int num = Integer.valueOf("22");
    num+=2;
    System.out.println(num); // output 24
}
urag
  • 1,228
  • 9
  • 28