NEWBIE: Math with wrapper classes?

Dear Experts,

I want to add 3 to the value of an Integer (not int).  (The result must remain an Integer). What's the industry-standard way?

Thanks,
BrianMc1958
BrianMc1958Asked:
Who is Participating?
 
CEHJCommented:
Integer i = 3;
i += 3;

(Java 5)

Integer i = new Integer(3);
int temp = i.intValue() + 3;
Integer i = new Integer(temp);

otherwise
0
 
rrzCommented:
Are you using Java 5 ?
0
 
BrianMc1958Author Commented:
Yikes!  I thought I was asking an insignificant question!

I'm using jre1.4.1_03.  I'm ignorant about Java 5.  

So first, does Java 5 = jre1.5 ?  

And far more importantly, does this mean we can then treat wrapper classes exactly as primitives ?!  (This would definitely rock my little world!)
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
Mayank SAssociate Director - Product EngineeringCommented:
>> does Java 5 = jre1.5

Effectively. The JDK means you have the kit for development and the JRE means you only have the stuff required for running (not developing).

>> does this mean we can then treat wrapper classes exactly as primitives

In Java 5, in your code - yes
0
 
CEHJCommented:
Yes and yes. Second yes (it's called autoboxing/unboxing)
0
 
BrianMc1958Author Commented:
Great.  Thanks again...
--BrianMc1958
0
 
CEHJCommented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.