🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #17621

Re: Converting a string number to integer

#17621
From: Michael A. Long
Date: Fri, 09 Oct 1998 00:00
63 lines
2565 bytes
Since we are optimizing this, you do not have to instanciate an object of type Integer in order to use its methods.  There is a name
for this type of class but it has eluded me.  Here is the optimized version:

int i = Integer.parseInt(txtField1.getText());

The advantage here is that there is no object instanciated and therefore it has NO scope rather than it sticking around for any
length of time.  Not that having it sticking around is a problem, just a mental exercise.

Dillan Fernando wrote in message <6vlqao$2jm8@forums.borland.com>...
>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: <6vmmeo$3hl27@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <361CDD1E.D3894642@netrisk.com> <MPG.1086bb539839fd1d9896a4@forums.borland.com> <361D16E6.CC7B2C81@netrisk.com> <6vlqao$2jm8@forums.borland.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: "Michael A. Long" <mlong@cmc.net>
Subject: Re: Converting a string number to integer
Date: 1998/10/09
Message-ID: <6vmmeo$3hl27@forums.borland.com>
X-Deja-AN: 399583735
References: <361CDD1E.D3894642@netrisk.com> <MPG.1086bb539839fd1d9896a4@forums.borland.com> <361D16E6.CC7B2C81@netrisk.com> <6vlqao$2jm8@forums.borland.com>
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
Organization: CSU Chico
Newsgroups: borland.public.jbuilder.java.language