Full width home advertisement

Post Page Advertisement [Top]

How to convert String to integer or integer to String in Java

In Java, String is a predefined class in Java which can hold String Value(array of Characters.).
If any string contain number such as "53", "21" , "110" and you want to use of Integer. It is not directly possible.

You can convert it by using Integer.parseInt(myStringNumber).

Example 1:

String m="45";
int a;
a = Integer.parseInt(m);

Example 2:

public int StringToInt(String number)
return Integer.parseInt(number);


Converting integer to number is so easy. Just add empty string before "" any number like this:

int a=5;
String m;
m= "" + a;

Example 3:

public String IntToString(int num)
return "" + num;

No comments:

Post a Comment

Bottom Ad [Post Page]

| Designed by Colorlib