Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For the handling of objects collection in Java, Collection interface have been provided. This is available in <code>java.util package</code>.</p> <p><strong>"List"</strong> is an interface, which extends collection interface, provides some sort of extra methods than collection interface to work with collections. Where as <strong>"ArrayList"</strong> is the actual implementation of "List" interface.</p> <p>The <strong>ArrayList class has only a few methods in addition to the methods available in the List</strong> interface. There is not much difference in this. The only difference is, you are creating a reference of the parent interface in the first one and a reference of the class which implements the List (i.e) the ArrayList class in the second. If u use the first, you will be able to call the methods available in the List interface and you cannot make calls to the new methods available in the ArrayList class.Where as, if you use the second one, you are free to use all the methods available in the ArrayList.</p> <p><strong>EDIT:</strong></p> <p>In Java Applications development, when you are supposed to pass the collection framework objects as arguments to the methods, then it is better to go with</p> <pre><code>List tempList = new ArrayList(); somemethodcall(tempList); </code></pre> <p>because, in future due to performance constraints, if you are changing the implementation to use linkedlist or some other classes which implements List interface, instead of ArrayList, you can change at only one point (i.e) only the instantiation part. Else you will be supposed to change at all the areas, where ever, you have used the specific class implementation as method arguments. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload