Link to home
Start Free TrialLog in
Avatar of Felipe1976
Felipe1976

asked on

How to Integer to a string

I Sorry for this quiestion but i dont have idea of how to do this
how can i convert a string to a integer
Felipe
Avatar of bobbit31
bobbit31
Flag of United States of America image

int x = Integer.parseInt("12345");
ASKER CERTIFIED SOLUTION
Avatar of dentrita
dentrita

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mick Barry
int i = 20;
String s = Integer.toString(i);
objects....

>> convert a string to a integer

String s = Integer.toString(i)  ??? Perhaps typed that a little too fast ;-) ?

Anyway, you can also use: int i = new Integer ( stringObject ).intValue (). However, it might be better to use Integer.parseInt ( stringObject ) as it is useless to instantiate an extra object.
Avatar of pradeepbkumar
pradeepbkumar

U can use the following example...

String str = "10";
int strValue = Integer.parseInt(str).intValue();

which would give the value 10 into the variable strValue.

Regards,
Pradeep
> String s = Integer.toString(i)  ??? Perhaps typed that a little too fast ;-) ?

Not really.
Perhaps Felipe1976 typed the question too fast :)

Q. "How to Integer to a string"
Is the question for Converting a string to an integer or the other way???

Regards,
Pradeep
String str1 = "101";
int intVal = Integer.parseInt(str1);


>> int strValue = Integer.parseInt(str).intValue();

No. Integer.parseInt () is enough. You cannot do an intValue () over a result from parseInt () because parseInt () returns a simple 'int and not an Integer object. Or else you can do: new Integer ( str ).intValue () -> but like I said, its a useless instantiation of an extra object.
Felipe1976,

We still don't know if you were trying to convert a String to an integer or an integer to a String?