Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java Collections

 
Selva Prakash
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any one tell me the easy way to keep difference between collections in mind?
 
Greg Charles
Sheriff
Posts: 2989
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.).
 
Srikanth Nalam
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
salvin francis
Bartender
Posts: 1305
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
+1 for Srikanth Nalam's answer,

To the point, and exactly answers OP's question.
 
Henry Wong
author
Marshal
Pie
Posts: 21364
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Selva Prakash
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i got some good point to keep collections in mind... thanks a lot.............
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic