Solved

Difference between ArrayList & Collections?

Posted on 2008-10-29
5
1,222 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

12 Experts available now in Live!

Get 1:1 Help Now