Solved

Difference between ArrayList & Collections?

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

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

821 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