Solved

Difference between ArrayList & Collections?

Posted on 2008-10-29
5
1,228 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 60

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 60

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 60

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

739 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