Results 1 to 7 of 7
  1. #1
    chann is offline Member
    Join Date
    Jan 2012
    Location
    Chennai
    Posts
    3
    Rep Power
    0

    Question Collection classes

    What is the advantage of classification of collection classes?

  2. #2
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default Re: 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.
    Last edited by j2me64; 01-18-2012 at 04:49 PM.

  3. #3
    chann is offline Member
    Join Date
    Jan 2012
    Location
    Chennai
    Posts
    3
    Rep Power
    0

    Default Re: Collection classes

    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

  4. #4
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default Re: Collection classes

    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.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: Collection classes

    There's the Collections tutorial.
    And the API for Collection which links to all the different types.

    That should cover it all...

  6. #6
    chann is offline Member
    Join Date
    Jan 2012
    Location
    Chennai
    Posts
    3
    Rep Power
    0

    Default Re: Collection classes

    Hi All,

    Thank you...!

    I will refer those links and will ask if I have any doubts in this topic.

  7. #7
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default Re: Collection classes

    Quote Originally Posted by Tolls View Post
    And the API for Collection which links to all the different types.
    @chann: Please not that there is a link to Map inside the API cor Collection but the interface Map doesn't inherit from Collection.

Similar Threads

  1. Replies: 5
    Last Post: 11-21-2011, 01:42 AM
  2. Serialization of Collection classes
    By me.anchit in forum Advanced Java
    Replies: 6
    Last Post: 09-23-2011, 12:57 PM
  3. Diff on Collection classes
    By mopurilakshmikarreddy in forum New To Java
    Replies: 1
    Last Post: 06-08-2011, 09:31 AM
  4. Collection Help
    By spartan in forum New To Java
    Replies: 2
    Last Post: 03-18-2011, 09:18 AM
  5. help for collection api
    By javastuden in forum New To Java
    Replies: 3
    Last Post: 02-24-2010, 11:52 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •