This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Inetger Wrapper Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Inetger Wrapper" Watch "Inetger Wrapper" New topic
Author

Inetger Wrapper

aakash bath
Greenhorn

Joined: Mar 15, 2002
Posts: 12
How to add a value in Integer object
An eg:
Integer no = new Integer();
no = no+1;
It throws an error why we have to convert in to primitive type int and add it.
Regards,
aakash
Elouise Kivineva
Ranch Hand

Joined: Feb 07, 2002
Posts: 154
The Integer constructor takes a parameter, either an int or a String. The parameter specifies the Integer's initial value.
You can't add one to a number until you know what that number is.
[ July 11, 2002: Message edited by: Elouise Kivineva ]
Mahesh Mamani
Ranch Hand

Joined: Jun 25, 2001
Posts: 110
Hi,
Also the return value of + is an integer, so u cannot directly assign it to Integer

MSM
aakash bath
Greenhorn

Joined: Mar 15, 2002
Posts: 12
Yes I missed the parameter
The statement
Integer t = new Integer(2);
t = t+1;
Throws an error
operator + cannot be applied to java.lang.Integer,int
Regards,
aakash
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
An Integer object, like other wrapper objects, is immutable. Once it is created, its state cannot be changed. You will just have to create a new Integer object.
Chad McGowan
Ranch Hand

Joined: May 10, 2001
Posts: 265
You can't change the value of the Integer object, but you can create a new one.
Try
Integer t = new Integer(2);
t = new Integer(t.intValue() + 1);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inetger Wrapper