Solved

Difference between ArrayList & Collections?

Posted on 2008-10-29
5
1,225 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now