Article View: borland.public.jbuilder.java.language
Article #17624Re: Converting a string number to integer
From: Dillan Fernando
Date: Sat, 10 Oct 1998 00:00
Date: Sat, 10 Oct 1998 00:00
52 lines
1923 bytes
1923 bytes
Hi Vasudevan.
Try this.
int i = new Integer("100").parseInt(txtField1.getText());
note: the "100" is just a dummy value to construct an Integer Class
Hope this helps !
Regards
Dillan Fernando
Senior Analyst
Palmware (pvt) Ltd.
Sri Lanka
Vasudevan Srinivasan wrote in message <361D16E6.CC7B2C81@netrisk.com>...
>Hi
>i had tried that one, but valueOf(...) returns Integer class not int type.
so
>i got a compilation error.
>anyway now i have rewritten the code as:
>int iv = (new Integer(text.getText()).intValue();
>but i would like to know the scope of this Integer class - thru out the
>existance of the program or only until the end of the function.
>thanks
>
>Max Polk wrote:
>
>> > String v = new String();
>> > JTextField text;
>> > int iv;
>> > ...
>> > v = text.getText();
>> > Integer integervalue = new Integer(v);
>> > iv = integervalue.intValue();
>> > ...
>> >
>> > is there any easy way to do this conversion bypassing declaration of
>> > extra variables/objects ?
>>
>> Yes -- try:
>>
>> int I = Integer.valueOf (text.getText ());
>>
>> Typically the "valueOf" methods convert things to an object of that type.
>> "valueOf" occurs coverting back to string as well, such as
>> String.valueOf() which accepts boolean, char, char[], double, float, int,
>> long, and so forth.
>
>
>
Technical Details
Message-ID:
<6vlqao$2jm8@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<361CDD1E.D3894642@netrisk.com> <MPG.1086bb539839fd1d9896a4@forums.borland.com> <361D16E6.CC7B2C81@netrisk.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,698598ce65fb7690 X-Google-Attributes: gidf74b3,public From: "Dillan Fernando" <dillan@geocities.com> Subject: Re: Converting a string number to integer Date: 1998/10/10 Message-ID: <6vlqao$2jm8@forums.borland.com> X-Deja-AN: 399467487 References: <361CDD1E.D3894642@netrisk.com> <MPG.1086bb539839fd1d9896a4@forums.borland.com> <361D16E6.CC7B2C81@netrisk.com> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4 Organization: Palmware Newsgroups: borland.public.jbuilder.java.language