• Post Reply Bookmark Topic Watch Topic
  • New Topic

Integer Class  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Integer s = new Integer(5)

Can we change the value of an Integer object s holding an primitive type int?
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why dont you try it out just a 2 line code .. right ?


Cheers !
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, an Integer object is immutable, just like all the other wrapper classes and class String.
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Debi Pany:
Integer s = new Integer(5)

Can we change the value of an Integer object s holding an primitive type int?


Why would you want to, if you need it mutable - just use the int directly.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!