Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 231

# 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
0
Felipe1976
• 3
• 3
• 2
• +3
1 Solution

Commented:
int x = Integer.parseInt("12345");
0

Commented:
toString
public String toString()
Returns a String object representing this Integer's value. The value is converted to signed decimal representation and returned as a string, exactly as if the integer value were given as an argument to the toString(int) method.

Overrides:
toString in class Object
Returns:
a string representation of the value of this object in base 10.

or can try

Integer.parseInt(x) converts String to int.
0

Commented:
int i = 20;
String s = Integer.toString(i);
0

Associate Director - Product EngineeringCommented:
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.
0

Commented:
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,
0

Commented:
> 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"
0

Commented:
Is the question for Converting a string to an integer or the other way???

Regards,
0

Commented:
String str1 = "101";
int intVal = Integer.parseInt(str1);

0

Associate Director - Product EngineeringCommented:
>> 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.
0

Commented:
Ok
0

Associate Director - Product EngineeringCommented:
Felipe1976,

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

## Featured Post

• 3
• 3
• 2
• +3
Tackle projects and never again get stuck behind a technical roadblock.