use int if you can, if can be null or used as an Object e.g. Generics, use Integer
- Prefer
intfor performance reasons - Methods that take objects (including generic types like
List<T>) will implicitly require the use ofInteger - Use of
Integeris relatively cheap for low values (-128 to
- because of interning - use
Integer.valueOf(int)and not new Integer(int)
- Do not use
==or!=with Integer types - Consider using
Integerwhen you need to represent the absence of a value (null) - Beware unboxing Integer values to int with null values