• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

string to integer conversion

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!

I need to change string "7777" to integer 7777, and integer 15 to string "15".

I would appreciate if you can help.

Thanks in advance,
Sanjul
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, the answer to both of your questions can be found in the Javadocs for the java.lang.Integer class.
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have posted the same question in your other thread.
It would be easy to follow if you post at only one place.

You should get your answers here
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Integer.html

String to int
int i = Integer.parseInt("7777");

you can have it in a try catch block or check to make sure that the string is indeed a valid number.
 
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sanjul,
You can convert int to String using Integer.



Remember, those will throw NumberFormatException if the string doesn't contain a valid value.

And about convert int to String you can use String.



Oh ya... now in J2SE 5.0, there is a new feature about convert between primitive data type and its wrapper class. It is Autoboxing/unboxing.
You can read at Autoboxing

Hope this help...
Correct me if I am wrong..

daniel
 
reply
    Bookmark Topic Watch Topic
  • New Topic