Monday, June 24, 2013

Don't know which map/collection to use?

This post will summarize about collection framework in a convenient way. This is continuation of the previous post about Collection Framework in Java

This diagram give you the basic understanding of when to use which collection.




This diagram give you the hierarchy of Collection framework with its ordering and sorting scenario.  








If you know anyone who has started learning java, why not help them out! Just share this post with them. Thanks for studying today!...

19 comments:

  1. A comprehensive diagram for deciding which Collection to use!

    ReplyDelete
  2. Nice - a picture paints a thousand words :-)

    ReplyDelete
  3. Thanks for the great pic, but I think LinkedLinked is also a good choice if you want duplicates

    ReplyDelete
    Replies
    1. I mean LInkedList not LinkedLinked

      Delete
    2. Actually, LinkedList is not the only choice for duplicates; there is also ArrayList, Vector, and Queue. That which you meant to say is that the List collection framework is the ideal choice for duplicates.

      Delete
  4. This was very nice summary. Thanks.
    Keep Posting !!!

    ReplyDelete
  5. duplicate? NO -->> searching? NO -->> Fast? NO -->> Sync? NO! then !!! ArrayList !!! NO DUPLICATE?

    ReplyDelete
  6. If synchronization is an issue, use the synchronized versions of the collection. See http://docs.oracle.com/javase/7/docs/api/java/util/Collections.html Don't use Vector unless it is for some of its other features like returning an Enumeration of its elements.

    Overall, I think it is a nice post, but there are so many more collections to consider. This is a good start, and useful to many developers.

    ReplyDelete
    Replies
    1. Thanks John for your valuable comment, and yes, you are right there are synchronized versions of the collection which I'll slowly introduced in the same flow chart.

      Delete
  7. Great pic! Is there something wrong with LinkedList? I can reach it from [do u want duplicates = NO]

    ReplyDelete
  8. There is an error if you follow the no path for duplicates where it leads to LinkedList, which does allow duplicates. That path should lead go LinkedHashSet.

    ReplyDelete
  9. This was very impressive summary. Thank You so much.
    As soon as possible you'll need to update it with IdentityHashMap [http://docs.oracle.com/javase/1.5.0/docs/api/java/util/IdentityHashMap.html]

    ReplyDelete
  10. Hello, I suggest to change stack to LIFO, it's not LILO.

    ReplyDelete
  11. Here Linked HashSet and Linked HashMap are missed from Most talked about Collection

    ReplyDelete