Local database reading edition

Which Integer statement works best?

Reconstructed from database records, not a captured original forum layout. Dates and display names are retained as recorded; timezone and real-world identity are not inferred. Historical advice, contact details and offers are not current. Original markup is shown as inert text.

Forum index · Java - Tips Of The Day

Opening post

Asha · 2001-02-15 13:11:09

Today's tip I am curious to discuss about the performance of following two statements? (1) <i> Integer.valueOf(&quot;7&quot;).intValue();</i> (2) <i> Integer.parseInt(&quot;7&quot;);</i> This is one of my favorite java coding level performance enhancement. Let's consider the first statement and decompose it a bit, <i> Integer temp_integer = Integer.valueOf(&quot;7&quot;); int temp_int = temp_integer.intValue(); </i> Breaking the code helps me to find out what's going on: when you call <i> Integer.valueOf(&quot;7&quot;); </i> --&gt; Integer parses String &quot;7&quot; and uses the parsed value to instantiate and initialize an Integer instance. <i> temp_integer.intValue();</i> retrieve int value from the instance. There is no need to parse 2nd statement <i> Integer.parseInt(&quot;7&quot;);</i> The only difference between the two lines is that the first example instantiates an extra Integer instance.Object instantiation can be expensive for you. But if you needed to use the Integer instance later then be sure to use <i> valueOf()</i> . Asha Balasubramanyan http://www.ammu.org

Source notes

MyCommunity/nandighosha.org.zip!/forum/tools/snitz_forums_2000.mdb
Table: FORUM_TOPICS + FORUM_REPLY · record IDs: 36