Are the
Integer a = new Integer(10);
and
Integer a = Integer.valueOf(10);
commands same?
Mayank Chandratre
Level 20
Will it be same?
Resolved
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Mayank Chandratre
5 November 2022, 18:20
Thanks..My problem is resolved
+1
Thomas
5 November 2022, 13:16useful
no, valueOf and autoboxing trigger caching (static Integer objects already initialized inside the Integer class for values form -128 to 127) while the constructor always creates a new instance. In addition to that the constructor is deprecated since 9.
+1