• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

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
0
BrianMc1958
Asked:
BrianMc1958
3 Solutions
 
rrzCommented:
Are you using Java 5 ?
0
 
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
 
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now