- Integer x = 5;
- Integer x = Integer.valueOf(5);
Is there any scenario where I would want to use the 2nd one specifically or is it redundant altogether and shouldn't not bother about it?
Both statements are equivalent.
The statement Integer x = 5
would be compiled to
Integer x = Integer.valueOf(5);
The compiler will do that for you behind the scene, so the only difference is the number of character in source file.
After Java 5 (because of autoboxing / unboxing) there is no difference except the first one is shorter.