Can any one tell me the code in java to convert string to int. What are the syntax and declaration commands are used to convert string to int. Any help will be extremely appreciated.
Can any one tell me the code in java to convert string to int. What are the syntax and declaration commands are used to convert string to int. Any help will be extremely appreciated.
You can convert a Java String to an int using the parseInt() method of the Integer class.The toString() method also convert Integer number to string number. The java.lang package provides this conversion functionality through toString() method. String can be converted into int in java by parseInt() method. Type casting is a method to change string to integer.
Code:import java.io.*; import java.lang.*; public class intst { public static void main(String[] avg) throws IOException{ BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); System.out.pn("Enter the value"); String st = read.readLine(); String d = new Integer(str).toString(); System.out.pn("String:=" +d); } }
string to int in java :
Code:public class strtoint { public static void main(String[] avg) { String stint="1234"; int M1=Integer.parseInt(str); // method 1 to convert string to int System.out.println("Type no string to integer :"+rM1); int M2=Integer.valueOf(str); System.out.prln("Type no string to integer :"+M2);
Bookmarks