File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes java Collections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java Collections" Watch "java Collections" New topic

java Collections

Selva Prakash
Ranch Hand

Joined: Sep 03, 2009
Posts: 41
Any one tell me the easy way to keep difference between collections in mind?
Greg Charles

Joined: Oct 01, 2001
Posts: 2969

Well, start by getting really good at the ones you will use the most. For example, learn the List interface and ArrayList implementation first. Once you're comfortable with those, you can use that understanding to learn some others, like Map and HashMap. You will start see start to see how things like Trees, Sets, linked lists, etc., all have certain differences that make them better to use in various situations.

Just as a carpenter doesn't learn about all the available tools first before trying to build something, a Java programmer can't hope to learn the whole API from a book (or a forum). Grab some nails and a hammer and start pounding away!
marc weber

Joined: Aug 31, 2004
Posts: 11343

Use the API to draw your own hierarchy chart of the different classes (what's a subclass of what, and what implements what). For each class, list the main advantages and disadvantages (for example, fast insertions in the middle vs. fast random access, etc.).

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
Srikanth Nalam

Joined: Feb 23, 2010
Posts: 20
The main criteria with which the collections differ are ordered, sorted

List - order of elements is guaranteed (ArrayList, LinkedList, Vector)

Set - duplicates not allowed (HashSet,LinkedHashSet, TreeSet)

Tree - Sorted (TreeMap, TreeSet)

Linked kind of data structure, order of elements is guaranteed (LinkedHashMap, LinkedHashSet)

However this can help you to remember only the basic differences. When it comes to detail, i think it will come with regular usage.

Thanks & Regards,
Srikanth Nalam.
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 1141

+1 for Srikanth Nalam's answer,

To the point, and exactly answers OP's question.

I agree. Here's the better link:

Henry Wong

Joined: Sep 28, 2004
Posts: 20538

salvin francis wrote:
To the point, and exactly answers OP's question.

Unless, of course, the OP is taking an algorithms class... and is trying to remember, the big O values for different types of operations on different collections -- meaning which collections access faster, iterates faster, etc.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Selva Prakash
Ranch Hand

Joined: Sep 03, 2009
Posts: 41
i got some good point to keep collections in mind... thanks a lot.............
I agree. Here's the link:
subject: java Collections
It's not a secret anymore!