aspose file tools*
The moose likes Beginning Java and the fly likes How to convert integer to string and string to integer? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to convert integer to string and string to integer?" Watch "How to convert integer to string and string to integer?" New topic
Author

How to convert integer to string and string to integer?

Mindy Wu
Ranch Hand

Joined: Jan 12, 2001
Posts: 121
I know a method to convert string to interger:
for example:
String strNum = "123";
int intNum = Integer.parseInt(strNum);
Is there are any other way to do the same thing?? By the way, how to use toString(); when should I include argument in the () and don't.
Mindy Wu
Art Metzer
Ranch Hand

Joined: Oct 31, 2000
Posts: 241
Hi, Mindy.
If you decide to go with your code, remember that parseInt() throws a NumberFormatException.
You could also use

To convert an int to a String, use any one of the following:

(This information from the Java FAQ.)
And, to my knowledge, the toString() method never takes any arguments. To use it, just call it from whatever object you'd like to see in string form: Integer.toString(), Object.toString(), etc. The resultant object will of course be a String.
Hope this helps, Mindy.
Art
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
You may want to look up the intValue() method. To convert in int to a string object, You can just wrap your in value using the Integer() method.
Bosun


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Mindy Wu
Ranch Hand

Joined: Jan 12, 2001
Posts: 121
Thank you all! That's really help me out!

Happy programmer!
Mindy
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to convert integer to string and string to integer?