Solved

Difference between ArrayList & Collections?

Posted on 2008-10-29
5
1,226 Views
Last Modified: 2012-05-05
When should I go for ArrayList? and when should I go for Collections? Can anyone explain me clearly the difference between these two?
0
Comment
Question by:GouthamAnand
  • 3
5 Comments
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22830178
I have always thought their syntax was identical just that Collection was for Object correlation -- could be totally different objects -- where as with ArrayList you are usually trying to store different instances of same type/Object especially with strongly typed Generic version ArrayList<?>.
http://www.developer.com/net/net/article.php/3403481

However, Collection could be used as an alternative to Arrays, here is Microsoft's take on it:
http://msdn.microsoft.com/en-us/library/e1ad18x6(VS.71).aspx
0
 
LVL 18

Accepted Solution

by:
DarrenD earned 500 total points
ID: 22830288
Hi,

If you are using .NET 3.0 then I would use a 'List<>'

This is a Generic List which gives type safety as opposed to an ArrayList. An ArrayList is also slower as it must box and unbox to a System.Object type.

However if you are exposing the array to different clients  on different platforms then you should probably use an normal array.

Mostly I'd use List<>. It's extremely easy to use and does not require you to keep track of array size and resizing.

Do you have any C# books? You can usually find pointers in them on when to use them etc.  

C# 3.0 Unleashed is quite good.

Hope this helps,

Darren
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22830768
I would agree.  In java you would use:

List<String> list = new ArrayList<String>();

I always forget that equivalent in .NET is just:

List<string> list = new List<string>();

I would also strongly suggest going with the type safe Generic.
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22830793
Whenever I see C# syntax, my brain switches over to Java. :) Guess that is why I use VB.NET sometimes (keep my mind straight as to whether I am in Java or .NET code ;)).
0
 

Author Closing Comment

by:GouthamAnand
ID: 31511113
Thank you.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question