File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java Collections" Watch "java Collections" New topic
Author

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
Sheriff

Joined: Oct 01, 2001
Posts: 2771
    
  10

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
Sheriff

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
sscce.org
Srikanth Nalam
Greenhorn

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: 917

+1 for Srikanth Nalam's answer,

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


My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18104
    
  39

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.

Henry


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: http://aspose.com/file-tools
 
subject: java Collections
 
Similar Threads
collections and generics
Collections
Garbage collection - arrays
List in Descending order
Collections