File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes collection classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "collection classes" Watch "collection classes" New topic

collection classes

madhur jain
Ranch Hand

Joined: Aug 27, 2002
Posts: 49
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)
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
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

Joined: Jul 03, 2001
Posts: 2120
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

SCJP2. Please Indent your code using UBB Code
I agree. Here's the link:
subject: collection classes
jQuery in Action, 3rd edition