473,386 Members | 1,720 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,386 software developers and data experts.

How-to Compare 2 arraylists

Hi all,

What is the best way to compare 2 (large) ArrayLists filled with an object.
Can you please help me?

Gaby
Nov 17 '05 #1
4 7559
Hi,

What you mean with "filled with an object" ?

If the array is of a user defined type I th ink that first it depend of how
you want it to compare them, you could compare if both arrays have the same
references, if so all you have to do is a foreach.

If you want to compare the objects itself it depend of the class.

Also remember to check for the size to be equal.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Gaby" <Ga**@discussions.microsoft.com> wrote in message
news:34**********************************@microsof t.com...
Hi all,

What is the best way to compare 2 (large) ArrayLists filled with an
object.
Can you please help me?

Gaby

Nov 17 '05 #2
Hi,

I need to compare 2 array lists with the same object type (cAddress).
public class cAddress
{
public string Address = "";
public string Number = "";
public string Zip = "";
public string City = "";
public string Country = "";
public string Telephone = "";
}

Every period the data from the database will be checked against the current
arraylist.
The lists will be filled with aprox 10000 objects.
No I want to know what the best and quickest way is.

Gaby

"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

What you mean with "filled with an object" ?

If the array is of a user defined type I th ink that first it depend of how
you want it to compare them, you could compare if both arrays have the same
references, if so all you have to do is a foreach.

If you want to compare the objects itself it depend of the class.

Also remember to check for the size to be equal.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Gaby" <Ga**@discussions.microsoft.com> wrote in message
news:34**********************************@microsof t.com...
Hi all,

What is the best way to compare 2 (large) ArrayLists filled with an
object.
Can you please help me?

Gaby


Nov 17 '05 #3
First step, make cAddress objects comparable. Basically, this means to
implement the IComparable interface (that is, define a CompareTo method for
it). You may also wnat to define an operator== for it.

Next, I'm going to assume that Current[i] corresponds to Database[i], in
which case it, it's just:

for(int i =0; i< Current.Length, ++i)
{
cAddress ad1 = Current[i];
cAddress ad2 = Database[i];
if (ad1.CompareTo(ad2) != 0)
return "Don't Match";
}
return "Match";

--
--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com

"Gaby" <Ga**@discussions.microsoft.com> wrote in message
news:BA**********************************@microsof t.com...
Hi,

I need to compare 2 array lists with the same object type (cAddress).
public class cAddress
{
public string Address = "";
public string Number = "";
public string Zip = "";
public string City = "";
public string Country = "";
public string Telephone = "";
}

Every period the data from the database will be checked against the current arraylist.
The lists will be filled with aprox 10000 objects.
No I want to know what the best and quickest way is.

Gaby

"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

What you mean with "filled with an object" ?

If the array is of a user defined type I th ink that first it depend of how you want it to compare them, you could compare if both arrays have the same references, if so all you have to do is a foreach.

If you want to compare the objects itself it depend of the class.

Also remember to check for the size to be equal.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Gaby" <Ga**@discussions.microsoft.com> wrote in message
news:34**********************************@microsof t.com...
Hi all,

What is the best way to compare 2 (large) ArrayLists filled with an
object.
Can you please help me?

Gaby


Nov 17 '05 #4
cheers....

"James Curran" wrote:
First step, make cAddress objects comparable. Basically, this means to
implement the IComparable interface (that is, define a CompareTo method for
it). You may also wnat to define an operator== for it.

Next, I'm going to assume that Current[i] corresponds to Database[i], in
which case it, it's just:

for(int i =0; i< Current.Length, ++i)
{
cAddress ad1 = Current[i];
cAddress ad2 = Database[i];
if (ad1.CompareTo(ad2) != 0)
return "Don't Match";
}
return "Match";

--
--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com

"Gaby" <Ga**@discussions.microsoft.com> wrote in message
news:BA**********************************@microsof t.com...
Hi,

I need to compare 2 array lists with the same object type (cAddress).
public class cAddress
{
public string Address = "";
public string Number = "";
public string Zip = "";
public string City = "";
public string Country = "";
public string Telephone = "";
}

Every period the data from the database will be checked against the

current
arraylist.
The lists will be filled with aprox 10000 objects.
No I want to know what the best and quickest way is.

Gaby

"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

What you mean with "filled with an object" ?

If the array is of a user defined type I th ink that first it depend of how you want it to compare them, you could compare if both arrays have the same references, if so all you have to do is a foreach.

If you want to compare the objects itself it depend of the class.

Also remember to check for the size to be equal.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Gaby" <Ga**@discussions.microsoft.com> wrote in message
news:34**********************************@microsof t.com...
> Hi all,
>
> What is the best way to compare 2 (large) ArrayLists filled with an
> object.
> Can you please help me?
>
> Gaby


Nov 17 '05 #5

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

Similar topics

4
by: Tom Szabo | last post by:
Just wandering how can you close a browser remotely. In some web applications the browser closes or refreshes periodically. How is that done and how can it be done through PHP? TIA, Tom
15
by: Reid Nichol | last post by:
Hello, I was wondering if I could control how many bytes are in an int and the byte order. In C/C++ I can use int32 but how do I do this in python? How can I control byte order?
0
by: v I n O | last post by:
hI Geeks Please do let me know how do i find how many instances sql server running on the single machine. or in the n/w my objective should with help of C#/vb.net
4
by: James Salisbury | last post by:
Hi, I was checking my parent's website salisbury.cabrera.net on google by entering villa rent spain cabrera I can see the required site, ranked at 4, but I am concerend by the return at 1 and 5...
2
by: Frances Del Rio | last post by:
http://www.emol.com/especiales/cocina_chilena/comida.asp this page is so neat (goes in pop-up..) how was this done? how do you give a layer (or div, I guess) a semi-transparency so you can still...
4
by: | last post by:
Developing, building, and testing. How do it the best? Learning from the world leader - Microsoft I'm very interested in how the developing/build/testing workflow @ Microsoft looks like. I...
4
by: Supra | last post by:
in vb6 listbox1.remove item 5 how will i do in vb.net? regards
7
by: anushhprabu | last post by:
#define q(k)main(){ return!puts(#k"\nPRABUq("#k")");} q(#define q(k)main(){return!puts(#k"\nq("#k")");}) guys i'm working on this code.. i got it fromnet.. how this is working.. anyone pls.....
0
by: candra | last post by:
Learn What Hackers Know? -General Hacking Information -Password Security -Scanning, Fingerprinting And Similar Techniques -How Hackers Attack Numerous Internet Services -How Hackers Attack Web...
2
by: belred | last post by:
i just read this blog about how many objects (types) are loaded for a hello world program in C#. http://blogs.msdn.com/abhinaba/archive/2008/09/15/how-many-types-are-loaded-for-hello-world.aspx ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.