In the Integer class, Integer.toString is a static method. So you don't have to create an Integer instance.
If you want to print out the int, it'll be lighter, faster, and more memory-saving if you write it in the former way. If you want to put the Integer value in the Collection and represent it as an object, you can create each object like the latter. Then it creates objects, so it's going to provide more functionality than just int.
© 2024 OneMinuteCode. All rights reserved.