Article View: aus.computers.java
Article #303Re: Help! String as Integer
From: Paul Murray
Date: Thu, 18 Jan 2001 00:16
Date: Thu, 18 Jan 2001 00:16
19 lines
1868 bytes
1868 bytes
"Luke Vanderfluit" <luke@chipcity.com.au> wrote in message
news:3A63FC90.3C832EFA@chipcity.com.au...
> Why doesn't the following code work?:
>
> String a = "yes";
> String b = "ls";
> int aa = Integer.valueOf("foo").intValue();
> int bb = Integer.valueOf("bar").intValue();
> System.out.println(aa);
> System.out.println(bb);
>
> This throws a NumberFormatException
The integer value of "1" is 1. The integer value of "2" is 2. What do you
imagine the integer value of "foo" is? "foo" is not a number.
If you need to parse text values as numbers, maybe you need to look at
java.text.ChoiceFormat
Technical Details
Message-ID:
<Gow96.4959$65.31077@newsfeeds.bigpond.com>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news.gv.tsc.tdk.com!falcon.america.net!sunqbc.risq.qc.ca!news.maxwell.syr.edu!intgwpad.nntp.telstra.net!newsfeeds.bigpond.com!not-for-mailReferences:
<3A63FC90.3C832EFA@chipcity.com.au>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d6db,7de64e08ee658586 X-Google-Attributes: gid10d6db,public X-Google-Thread: 113ae9,7de64e08ee658586 X-Google-Attributes: gid113ae9,public X-Google-Thread: 10a146,7de64e08ee658586 X-Google-Attributes: gid10a146,public X-Google-ArrivalTime: 2001-01-17 23:06:49 PST Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news.gv.tsc.tdk.com!falcon.america.net!sunqbc.risq.qc.ca!news.maxwell.syr.edu!intgwpad.nntp.telstra.net!newsfeeds.bigpond.com!not-for-mail From: "Paul Murray" <pmurray@nospam.bigpond.com> Newsgroups: aus.computers.java,comp.lang.java.programmer,comp.lang.java.help References: <3A63FC90.3C832EFA@chipcity.com.au> Subject: Re: Help! String as Integer Lines: 21 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.3018.1300 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.3018.1300 Message-ID: <Gow96.4959$65.31077@newsfeeds.bigpond.com> Date: Thu, 18 Jan 2001 11:16:34 +1100 NNTP-Posting-Host: 203.54.251.249 X-Trace: newsfeeds.bigpond.com 979800742 203.54.251.249 (Thu, 18 Jan 2001 17:52:22 EST) NNTP-Posting-Date: Thu, 18 Jan 2001 17:52:22 EST Organization: Telstra BigPond Internet Services (http://www.bigpond.com)