Meaningless Drivel is fun!
The moose likes Beginning Java and the fly likes string to integer conversion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "string to integer conversion" Watch "string to integer conversion" New topic

string to integer conversion

Sanjul Jain

Joined: Oct 21, 2004
Posts: 14

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,
Chris Dempsey

Joined: Feb 24, 2004
Posts: 9
Well, the answer to both of your questions can be found in the Javadocs for the java.lang.Integer class.
rahul V kumar
Ranch Hand

Joined: May 20, 2003
Posts: 82
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

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.
Fisher Daniel
Ranch Hand

Joined: Sep 14, 2001
Posts: 582
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..

I agree. Here's the link:
subject: string to integer conversion
It's not a secret anymore!