Click here to Skip to main content
13,445,311 members (40,527 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


16 bookmarked
Posted 21 Dec 2014

What is the Difference between ArrayList and List Class?

, 21 Dec 2014
Rate this:
Please Sign up or sign in to vote.
ArrayList is a non-generic collection class and resides in System.Collection namespace whereas List is a generic class and resides in System.Collections.Generic namespace


This is one of my favorite interview questions. This question helps me to find out if candidate has good knowledge of generics or not. On the internet, there are a number of writeups on "difference between Array and ArrayList" but I didn't find any on "difference between ArrayList and List", so I am posting one...

Must Know

First, one should know what is upcasting? Upcasting is converting derived type into base type. In .NET, all data-types are derived from Object. So we can typecast any type to Object type. For example, if Customer is class, then we can create object of Customer like this:

Object cust = new Customer()

Here new Customer() will create object on heap and its address we are putting in reference variable of type Object.


ArrayList marks = new ArrayList();

In the above code snippet, we are creating object of ArrayList and adding different type of data in it. But actually ArrayList is a collection of Object type, and when we add any item to ArrayList, it first converts it to object type (upcasting) and then adds it to collection object.

Interesting Fact: As ArrayList can only create collection for Object type, it is said to be non-generic class. It might be confusing as it seems that we can add any datatype value like int, float, string to ArrayList collection so in that sense it should be called as generic class. But in fact, it internally converts all these datatypes in object type and then adds to collection.

We can visualise it as:


List<int> marks = new List<int>();


In the above snippet, we can observe that while creating object of list class, we have mentioned datatype of collection we want to create. We need to pass datatype while creating object as List class doesn’t hard code it internally. So the above declaration will create marks as collection of integers; and not collection of objects as in case of ArrayList.

We can visualize it as:

Interesting fact: In the above collection “marks” you can only add integers and no other type. In that sense, it should be referred to as non-generic! But wait, using the same List class, you can also create collection of string type:

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

Or even you can create collection of custom types. For example, collection of Student type can be created as:

List<Student> students = new List<Student>(); 

And as using same List class, now you are able to create collection of any data-type as integers, strings or students; this class is known as Generic class.

One of the benefits of using generic collection is no need of boxing and unboxing while tackling with collections of value types.

We can visualise List of string type (or any ref type) as:


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

13+ Years of Experience. Seen death and rise of various technologies. Started with VB - 6.0 back in 2004, then updated to .NET somewhere in 2008. used Win Forms, ASP.NET Web Forms. Switched to ASP.NET MVC in 2013 for very short time. Right now using ASP Core since 2015 when it was in RC 1.

You may also be interested in...


Comments and Discussions

QuestionUse of ArrayList Pin
Member 228277930-Jun-16 0:27
memberMember 228277930-Jun-16 0:27 
AnswerRe: Use of ArrayList Pin
vaynenick6-Oct-16 20:52
membervaynenick6-Oct-16 20:52 
GeneralModifying object in list. Pin
Member 228277930-Jun-16 0:25
memberMember 228277930-Jun-16 0:25 
Praiseacknowledge Pin
Member 1245206120-Apr-16 15:01
memberMember 1245206120-Apr-16 15:01 
QuestionWhat If, if I add generic to ArrayList Pin
Member 121044841-Nov-15 3:19
memberMember 121044841-Nov-15 3:19 
AnswerRe: What If, if I add generic to ArrayList Pin
Member 121044841-Nov-15 3:22
memberMember 121044841-Nov-15 3:22 
GeneralIt still seems backwards - that Lists are Generic Pin
smhiker11-Sep-15 9:41
membersmhiker11-Sep-15 9:41 
GeneralRe: It still seems backwards - that Lists are Generic Pin
Member 1306353616-Mar-17 5:08
memberMember 1306353616-Mar-17 5:08 
QuestionGood One Pin
Sachin Kumar21-Jun-15 12:31
memberSachin Kumar21-Jun-15 12:31 
QuestionAvoid ArrayList Pin
Andreas Haeni26-Dec-14 23:34
memberAndreas Haeni26-Dec-14 23:34 
GeneralMy vote of 3 Pin
Nam122222-Dec-14 13:30
memberNam122222-Dec-14 13:30 
GeneralMy vote of 3 Pin
NGzero22-Dec-14 13:11
memberNGzero22-Dec-14 13:11 
QuestionEquivalent in VB Pin
PlazmaSoft21-Dec-14 21:16
memberPlazmaSoft21-Dec-14 21:16 
AnswerRe: Equivalent in VB Pin
Bhushan Mulmule21-Dec-14 22:11
professionalBhushan Mulmule21-Dec-14 22:11 
GeneralMy vote of 5 Pin
Humayun Kabir Mamun21-Dec-14 19:01
memberHumayun Kabir Mamun21-Dec-14 19:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02-2016 | 2.8.180314.2 | Last Updated 21 Dec 2014
Article Copyright 2014 by Bhushan Mulmule
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid