Solved

How to Integer to a string

Posted on 2004-03-25
11
219 Views
Last Modified: 2010-03-31
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
Comment
Question by:Felipe1976
  • 3
  • 3
  • 2
  • +3
11 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 10684062
int x = Integer.parseInt("12345");
0
 
LVL 1

Accepted Solution

by:
dentrita earned 100 total points
ID: 10684085
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
 
LVL 92

Expert Comment

by:objects
ID: 10684101
int i = 20;
String s = Integer.toString(i);
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 10684349
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
 

Expert Comment

by:pradeepbkumar
ID: 10684514
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 92

Expert Comment

by:objects
ID: 10684556
> 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
 

Expert Comment

by:pradeepbkumar
ID: 10684584
Is the question for Converting a string to an integer or the other way???

Regards,
Pradeep
0
 

Expert Comment

by:sharmapradeepk
ID: 10684603
String str1 = "101";
int intVal = Integer.parseInt(str1);


0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 10684632
>> 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
 

Expert Comment

by:pradeepbkumar
ID: 10684647
Ok
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 10713681
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now