1.

In Java, how do you convert a string to an integer and vice versa?

Answer»

There is an Integer class in the JAVA lang package that provides different methods for converting strings to INTEGERS and VICE versa. The parseInt() method allows you to convert a String into an integer and the toString() method allows you to convert an Integer into a String. Below is a Java PROGRAM to convert a string to an integer and vice versa.

Example: 

public class StringtoInteger { public static void main(String args[]) { String STR1 = "1296"; int i= Integer.parseInt(str1); System.out.println(i); String str2 = Integer.toString(i); System.out.println(str2); }}

Output:

12961296


Discussion

No Comment Found