Bookmark Topic Watch Topic
  • New Topic

What is the difference between int maxrows=20 and using Integer maxRows=new Integer(20);?  RSS feed

 
Sowm Herur
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Report post to moderator

What is the difference between int maxrows=20 and using Integer maxRows=new Integer(20);?

Can we use int maxrows=20 to store maxrows instead of using Integer maxRows=new Integer(20);?

In what scenarios do we decide on what to use when?

Please Clarify
 
Leandro Coutinho
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Report post to moderator
int x = 10; // x is primitive
Integer y = new Integer(10); // y is a reference to an object

Primitives can't invoke methods of its wrapper classes.
Primitives can't be null, while objects can.
 
Campbell Ritchie
Marshal
Posts: 56553
172
  • Mark post as helpful
  • send pies
  • Report post to moderator
Closing as duplicate.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!