473,383 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Compare ArrayList

Hi,

I declare two ArrayList variables.How can I compare if the two ArrayList are
Value Equal.

Thanks!

Ben
Nov 16 '05 #1
1 29806
If you want to compare if the two arraylist variables refer to the same
arrayList object then you can use the ArrayList.Equals method, which
compares the object references.

But i guess you want to comapre the contents of the array list to check
if the contents are equak or not. You will have to write your own method
to do that, something along the lines of

priavte bool CompareArrayLists(ArrayList arr1,ArrayList arr2)
{
//Check if the two arraysLists have the same length
if(arr1.Count != arr2.Count)
return false;

//Iterate through each element and compare if it is equal to the
corresponding element in the other

for(int i=0;i<arr1.Count;i++)
{
if(!arr1[i].Equals(arr2[i]))
return false;
}

return true;
}

Of course the objects contained in the array lists should be comparable.
If they are custom objects then you can either override the Equals
vritual method, or use the ICompare interface.

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

bengamin wrote:
Hi,

I declare two ArrayList variables.How can I compare if the two ArrayList are
Value Equal.

Thanks!

Ben

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: David zhu | last post by:
I've got different result when comparing two strings using "==" and string.Compare(). The two strings seems to have same value "1202002" in the quick watch, and both have the same length 7 which I...
4
by: Sasidhar Parvatham | last post by:
Hi All, How do I compare two strings and get all the positions where there is a difference between them? Thanks, Sasidhar
4
by: Gaby | last post by:
Hi all, What is the best way to compare 2 (large) ArrayLists filled with an object. Can you please help me? Gaby
7
by: Terry | last post by:
I've got a situation where I have a set of data, and later take another snapshot to obtain a second set of data. There will be one or more changes in the second set of data and I need to be able...
0
by: jrthor2 | last post by:
I have a .net application that is using microsofts locator service. I have this working, but when I select a user to locate from my contact list, it comes back with a map, but the pushpin has the...
3
by: Sam | last post by:
Hi Everyone, I have a stucture below stored in an arraylist and I want to check user's input (point x,y) to make sure there is no duplicate point x,y entered (string label can be duplicated). Is...
27
by: sandyw | last post by:
Hi Everyone. Need some help. I have no ideal how to start this. my arlist is as followed static ArrayList arlist; arlist = new ArrayList<ticket>() I do not know where to go after this how do...
3
by: raylopez99 | last post by:
This is an example of using multiple comparison criteria for IComparer/ Compare/CompareTo for List<and Array. Adapted from David Hayden's tutorial found on the net, but he used ArrayList so the...
5
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I have a Container that is an an Array List of Class Each ArrayList element can be the class or a another ArrayList of Class So there the ArrayList could look like Element 1 - Class...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.