Last updated 2004-06-28 by Roedy
Green ©1996-2004 Canadian Mind Products
Java definitions: 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
You are here : home : Java Glossary : I words : int vs Integer.
To properly understand the difference, you should read an introductory textbook on Java. I will make a small stab at answering here.
Everything I say here applies analogously to char and Character, short and Short, long and Long, float and Float, double and Double.
An Integer, is a Object that contains a single int field. An Integer is much bulkier than an int. It is sort like a Fedex box to contain the int. Integers are immutable. If you want to affect the value of a Integer variable, the only way is to create a new Integer object and discard the old one.
| int vs Integer | ||
|---|---|---|
| ability | unboxed
int |
boxed
Integer |
| Calculate with it, + - * / % ^ etc. | yes | no |
| Pass it as a parameter | yes | yes |
| return it as a value | yes | yes |
| Use methods on it from java.lang.Integer | no | yes |
| Store it in a Vector or other Collection | no | yes |
| Use it as a HashMap key | no | yes |
| serialize it | no | yes |
| send it by itself over RMI | no | yes |
| send it as part of another Object over RMI | yes | yes |
// to int i from Integer ii int i = ii.intValue(); // to Integer ii from int i Integer ii = new Integer( i );
See this Amanuensis for other conversions.
home |
Canadian Mind Products | |||
| mindprod.com IP:[24.87.56.253] | ||||
| Your IP:[80.134.30.163] | ||||
| You are visitor number 1675. | ||||
| Please send errors, omissions and suggestions | ||||
| to improve this page to Roedy Green. | ||||
| You can get a fresh copy of this page from: | or possibly from your local J: drive mirror: | |||
| http://mindprod.com/jgloss/intvsinteger.html | J:\mindprod\jgloss\intvsinteger.html | |||