Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

collection classes

 
madhur jain
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all!
can someone tell me when i should use Arrays and when should i use collection classes to store different type of refrences (objects)
madhur.
 
Barkat Mardhani
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The arrays and collection have their own pro and cons. You have outline your requirement in terms of these pros and cons, then the choice becomes very easy. One thing to remember is that there is no absolute anser such as "always use arrays.."
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The main reason to use collections is that their size isn't fixed as with arrays.
Another advantages are that some containers have some useful behaviour built-in. It would be possible to simulate it with arrays, but it's already there for us.
a) when you need an associative array use some kind of Map.
b)you need some set operations? use some kind of Set
c) you need a stack ? use a LinkedList
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic