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
  • Last Modified:

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
Asked:
Felipe1976
  • 3
  • 3
  • 2
  • +3
1 Solution
 
bobbit31Commented:
int x = Integer.parseInt("12345");
0
 
dentritaCommented:
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
 
objectsCommented:
int i = 20;
String s = Integer.toString(i);
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Mayank SAssociate 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
 
pradeepbkumarCommented:
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
0
 
objectsCommented:
> 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
 
pradeepbkumarCommented:
Is the question for Converting a string to an integer or the other way???

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


0
 
Mayank SAssociate 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
 
pradeepbkumarCommented:
Ok
0
 
Mayank SAssociate 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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