469,300 Members | 2,376 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,300 developers. It's quick & easy.

Converting String to Integer

I'm a newbie and I'm sorry this is so basic but . . . .

If I have a String containing "123", how do I convert it to an Integer
variable?

I've tried all kinds of Integer.valueOf("123") permutations but the compiler
won't have it!

What's the trick?

TIA

Peter / London
Jul 17 '05 #1
4 185680
Peter Warder wrote:
I'm a newbie and I'm sorry this is so basic but . . . .

If I have a String containing "123", how do I convert it to an Integer
variable?

I've tried all kinds of Integer.valueOf("123") permutations but the compiler
won't have it!

What's the trick?

TIA

Peter / London

int a = new Integer("123").intValue();

Jul 17 '05 #2
Joe
In article <Tm***************@news-binary.blueyonder.co.uk>,
pw*****@blueyonder.co.uk says...
I'm a newbie and I'm sorry this is so basic but . . . .

If I have a String containing "123", how do I convert it to an Integer
variable?

I've tried all kinds of Integer.valueOf("123") permutations but the compiler
won't have it!

What's the trick?

TIA

Peter / London

int i = Integer.parseInt("123"); // catch a NumberFormatException

Keep this URL handy:
http://java.sun.com/j2se/1.4.1/docs/api/

--
"Everybody plays the fool. Sometimes."
-- American Folk Saying
Jul 17 '05 #3
Thanks
Peter
"Joe" <sf***@spamcop.net> wrote in message
news:MP************************@sfo.news.speakeasy .net...
In article <Tm***************@news-binary.blueyonder.co.uk>,
pw*****@blueyonder.co.uk says...
I'm a newbie and I'm sorry this is so basic but . . . .

If I have a String containing "123", how do I convert it to an Integer
variable?

I've tried all kinds of Integer.valueOf("123") permutations but the compiler won't have it!

What's the trick?

TIA

Peter / London

int i = Integer.parseInt("123"); // catch a NumberFormatException

Keep this URL handy:
http://java.sun.com/j2se/1.4.1/docs/api/

--
"Everybody plays the fool. Sometimes."
-- American Folk Saying

Jul 17 '05 #4
Thanks
Peter
"Boris Tabenkin" <le******@yahoo.com> wrote in message
news:GGLcb.430795$Oz4.229697@rwcrnsc54...
Peter Warder wrote:
I'm a newbie and I'm sorry this is so basic but . . . .

If I have a String containing "123", how do I convert it to an Integer
variable?

I've tried all kinds of Integer.valueOf("123") permutations but the compiler won't have it!

What's the trick?

TIA

Peter / London

int a = new Integer("123").intValue();

Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Ken Fettig | last post: by
13 posts views Thread by Gil | last post: by
4 posts views Thread by rainmaker1234 | last post: by
9 posts views Thread by priyanka | last post: by
1 post views Thread by sake | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.