2
Integer a = new Integer(100);
int ax = a; 

Is the above code same as below? If yes then what is the use of intValue() method since we can directly assign value to primitive int?

Integer a = new Integer(100);
int ax = a.intValue();
  • 4
    Does this answer your question? [What is .intValue() in Java?](https://stackoverflow.com/questions/11490425/what-is-intvalue-in-java) – fuat May 01 '21 at 19:31
  • Well, the reason you can write the former is because of auto-boxing. And auto-boxing calls `intValue` to do the job. Take a look at the code after compilation and you will see that both are equivalent. – Zabuzard May 01 '21 at 19:39
  • @fuat Yup! Thank You – Helsinki Red May 01 '21 at 20:19

0 Answers0