String can be converted into int in java by parseInt() method. Type casting is a method to change string to integer.
Example of converting string to int
public class StringToIntConvertExample { public static void main(String[] args) { String string_to_int="1234"; int numberM1=Integer.parseInt(string_to_int); // method 1 to convert string to int System.out.println("Type cast string to integer :"+numberM1); int numberM2=Integer.valueOf(string_to_int); // method 2 to convert string to int System.out.println("Type cast string to integer :"+numberM2); } }
Output
Type cast string to integer :1234
Type cast string to integer :1234
Tags: typecast



Link to Us
thanks there it work and helps me a lot
You should have to put a catch block for possible NumberformatException as well.
source: <a href=\\"http://javarevisited.blogspot.com/2011/08/convert-string-to-integer-to-string.html\\">String to Int to String conversion examples</a>