What is the advantage of classification of collection classes?
Printable View
What is the advantage of classification of collection classes?
a classification of collection classes let you for example group collection classes that have the same functionality. for example all classes of the Set interface don't let you add dublicates in the collection.
i'm not sure if i have understood your question correctly. if so clarify your question.
Hi Comrade,
Thanks for ur reply.
But, I asked, there are many classes in Collection. Why they separate it like ArrayList, LinkedList, Set, Map and all.
What is the unique advantage of these classes.
I am new to Java. So, can u give some exercises to explore about the collection classes.
Once again. my thanks for ur response:(handshake):
As I already mentioned List, Set, Map and Queues specify a different functionality. So also the implementing classes are classified depending on its interface.
Ok, let's look a little closer to the interface List. There are tree classes that implement this interface: Vector, ArrayList and LinkedList. All elements in the collection are ordered by index. But, Vector is synchronized and ArrayList is not. So the ArrayList has a faster access. The LinkedList seems to be obsolet, but it's not. When you insert a new element at a specific position in a ArrayList all subsequent elements must be moved and this will result in many cpu operations. In a LinkedList all elements a double linked. So when you insert a new element in a LinkedList only the reference to the next and previous element must be changed to refer the new element and this will be faster and with a low number of cpu operations. So if have a lot of inserts and deletes a LinkedList will be more appropriate than a ArrayList. But if the request is to have no deletes and the inserts are made at the end of the list and there is no need for thread safety an ArrayList is ok. Maps are used when you want to store pairs of keys and values and Set when you don't allow duplicates in your collection. Look at the collection cheat sheet for more details: Guide to Selecting Appropriate Map/Collection in Java
Please note that this topic is very extensive and can't explain each detail in a post so for a general question the answer will be general but for a specific question I can give a detailed answer.
There's the Collections tutorial.
And the API for Collection which links to all the different types.
That should cover it all...
Hi All,
Thank you...!
I will refer those links and will ask if I have any doubts in this topic.:(clap):