ArrayList of Objects

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I am running with a specific problem ,I have 2 arraylists of object types.I
need to compare the 2 arraylists and I have to figure out the first
sequence of common objects in each array starting from index 0,then I have to
takeout the common objects and then all other object from the second array
list.

Thx
Satya
 
Satya,

The first sequence of common objects? Does it count if only one object
matches up with another object? Or does the sequence have to have some
length?
 
Satya said:
I am running with a specific problem ,I have 2 arraylists of object types.I
need to compare the 2 arraylists and I have to figure out the first
sequence of common objects in each array starting from index 0,then I have to
takeout the common objects and then all other object from the second array
list.

Like Nicholas, I'm slightly confused as to what you're asking.

Could you give a few examples using lists of strings?

Jon
 
Satya,

I'm not completely sure, but I think what you're asking for is a
distinct union of two collections right? If so then try the following
code which takes two collections and returns a new collection
containing the result of the union.

public ICollection Union(ICollection lhs, ICollection rhs)
{
Hashtable table = new Hashtable();

foreach (object element in lhs)
{
if (!table.Contains(element))
{
table.Add(element, element);
}
}

foreach (object element in rhs)
{
if (!table.Contains(element))
{
table.Add(element, element);
}
}

return result.Values;
}

Brian
 
Back
Top