Object or primitive type

Can someone explain me using Integer, Boolean, etc. instead of their primitive types in JAVA?

I can’t understand what benefits they provide. They seem to create unnecessary problems with handling null values.

Thank!

+5
source share
4 answers

Boolean, Integer, Long, ... are objects. You can use them in places where you cannot use primitive types, for example.

  • keeping them in the collection as Map
  • using them as a template parameter
  • assigning them a value null
  • using them in a more general way (like Longhow Number)

<strong> Examples:

new ArrayList<Integer>();
Long id = null;
Number num = new Long( 3 );
+8
source

Integer, Boolean .. , . API- , , , , .., .

, :

List<Integer> list = new ArrayList<Integer>();

:

List<int> list = new ArrayList<int>();

, , "" API- , , ( ) Vector Hashtable, ilk.

+4

, NULL, , , # . null -1.

, , , (Double Integer Number).

+4

.
, :
1. . Number ( : Integer, Float ..) .
2. null. , . , . , db NULL, .
3. , , ( ). .
4. , getHashcode(), toString() .., .

+1
source

All Articles