On Mar 22, 5:17 am, column.col...@gmail.com wrote:
> Helo,
>
[quoted text clipped - 6 lines]
>
> Thank You
Yes, like the documentation says, Integer (and all the primitive
wrapper classes) objects are immutable. However, if you're using Java
5 or later, you don't need to write out the unpacking to an int and
creation of new Integers yourself: the language will automatically
unbox and box primitives into their respective wrappers.
You could write the above as
Integer i = 10;
Integer j = i / 2;
and let Java worry about the rest. Alternately, you could use int
instead of Integer.
-o
RedGrittyBrick - 22 Mar 2008 12:32 GMT
> On Mar 22, 5:17 am, column.col...@gmail.com wrote:
>> Helo,
[quoted text clipped - 21 lines]
> and let Java worry about the rest. Alternately, you could use int
> instead of Integer.
You can also write the OP's expression as
Integer i = 10;
i = i / 2;
Which the OP should find is not as "cumbersome".
> I need to divide Integer value by 2. Is it only one method to create
> new Integer? Looks cumbersome.
>
> Integer i = new Integer(10);
> ...
> /*Integer*/ i = New Integer(i.intValue()/2);
My guess is that you should use:
int i = 10;
i = i / 2;
and wrap in Integer when you need it.
Arne
>I need to divide Integer value by 2. Is it only one method to create
>new Integer? Looks cumbersome.
>
>Integer i = new Integer(10);
>...
>Integer i = New Integer(i.intValue()/2);
You can use primitive ints or let autoboxing simplify the code.
see http://mindprod.com/applet/converter.html

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com