File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to convert integer to string and string to integer?

 
Mindy Wu
Ranch Hand
Posts: 121
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 241
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mindy Wu
Ranch Hand
Posts: 121
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all! That's really help me out!

Happy programmer!
Mindy
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic