Let’s discuss some properties of the interfaces we have in collection:
Above are the given common methods of collection, which every interface implements in collection.
Here, some properties which will help you to understand , which interface is best for your application, according to given requirements.
It is child interface of Collection.
If we ant to represent a group of individual objects as a single entity where duplicates are allowed and insertion order must be preserved(means order is not important), then we should go for list.
=Underlying data structure in arrayList is resize able array , as it is under List so duplicates are allowed and order is preserved.
=Heterogeneous objects(different type of) can be inserted .
=null insertion is also possible.And it implements RandomAccess interface which allows us to make retrieval operations easily
=Best choice Array List when our frequent operation is retrieval operation.
=worst choice when our frequent operation is insertion or deletion in middle.
=underlying data structure is doubly Linked List
=And it inherit all properties of Array List except RandomAccess interface.
=That’s why LinkedList is best choice when our frequent operation is insertion or deletion in the middle, worst choice when frequent operation is retrieval.
=underlying data structure is array .
=All properties of ArrayList
=In vector most of the methods are synchronized, that’s why is it thread safe.
=Best choice for retrieval .
=It is child interface of vector.
=specially designed for Last In First Out operation.
=Underlying data structure is Hash Table
=duplicates are not allowed , If we are trying to insert duplicates, we won’t get any compilation error or runtime error , add() method simply returns false.
=Insertion order is not preserved , all objects inserted according to hash code.
=Heterogeneous objects are allowed.
=Null insertion is possible.
=No implementation of RandomAccess interface.
=Best choice for search operations.
=underlying data Structure is Hash Table + Linked List .
=Best choice to develop cache based applications where duplicates are not allowed and insertion order must be preserved.
=It is child interface of set.
=If we want to represent a group of individual objects according to some sorting order, then we must go for SortedSet.
=underlying data structure is balanced tree.
=duplicates are not allowed.
=Insertion order is not preserved , but there should be some sorting order.
=Heterogeneous objects are not allowed, if we try to insert then we will get runtime exception saying ClassCastException.
=Null insertion is allowed , but only for once.
thanks for giving your valuable time.