ArrayList aList = new ArrayList();
List aList = new ArrayList();
What's the difference between these two and which is better to use and why?
List is an Interface, whereas ArrayList is an implementation of that interface.
The second is better because it means you can change your ArrayList for another implementation of List later without needing to change the rest of your application. You may want to do this for performance reasons, or because of other aspects of the behaviour of the List implementation that you have chosen/will choose.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With