• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

something about primitive

 
max tan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the different between int and Intenger?
help me thank you!
 
Manish Hatwalne
Ranch Hand
Posts: 2595
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int is a primitive, whereas Integer is a wrapper class that represents primitive int. Often, while dealing with Java collection classes (Vector, HashSet...), Object methods you require to pass them an object as an argument, instead of a primitive. In such cases Wrapper classes come in handy. They also define values such as Double.NaN etc.
You can modify primitive variable value anytime, wrapper class objects on the eother hand, are immutable.
HTH,
- Manish
 
Barkat Mardhani
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Manish:

You can modify primitive variable value anytime, wrapper class objects on the eother hand, are immutable.

I thought that only String objects are immutable. Can we not change the primitive stored in an
Integer object?
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not unless there's a method to do so. And there isn't one.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic