What is the difference between these two lines?
int pInt = 500;
and
Integer wInt = new Integer(pInt);
Or
Integer wInt = new Integer(500);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
None.
That’s the exact same thing. In the first case you just have a supplementary variable.
Note that with autoboxing you rarely need to have both an
intand anIntegervariables. So for most cases this would be enough :The main case where the Integer would be useful is to distinguish the case where the variable is not known (ie
null) :But don’t keep two variables, one is enough.