473,508 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ArrayList subtract?

I have two arraylists, one with a list of groups and one with a list of
groups assigned to a user. I would like to subtract the second AL from the
first AL to get an AL of groups to which the user *isn't* assigned. Is
there an easy way to do this?

Thanks,

Craig
Nov 20 '05 #1
2 2295
yes, but i'd suggest you move to another data structure such as the dataset
with two datatables which will allow you to manage relationships much easier
than looping over two arraylists in a nested for loop. one issue if you
decide to go the second route it you have to store the elements you wish to
remove in a third list and then iterate that list to remove from the second
list.... because you can't modify the underlying list while using an
ienumerator base on it. datasets look a lot better dont they?
"Craig Buchanan" <so*****@microsoft.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have two arraylists, one with a list of groups and one with a list of
groups assigned to a user. I would like to subtract the second AL from the first AL to get an AL of groups to which the user *isn't* assigned. Is
there an easy way to do this?

Thanks,

Craig

Nov 20 '05 #2
Craig,
As Drew suggested, create a third AL that is your result, for each item in
the first, if it is not in the second add it to your result.

Something like:

Dim groups As New ArrayList
Dim assigned As New ArrayList
Dim result As New ArrayList

groups.Add("one")
groups.Add("two")
groups.Add("three")

assigned.Add("two")

For Each group As Object In groups
If not assigned.Contains(group) Then
result.Add group
End If
Next

Instead of an ArrayList however I would use a GroupCollection object that
contains individual Group objects, where GroupCollection inherits from
either DictionaryBase or CollectionBase depending on whether it is a "keyed"
collection or not. The above code would be a function of the GroupCollection
object.

Public Class GroupCollection
Inherits CollectionBase

...

Public Function GetDifference(...) ...
For Each group As Object In InnerList
Hope this helps
Jay

"Craig Buchanan" <so*****@microsoft.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have two arraylists, one with a list of groups and one with a list of
groups assigned to a user. I would like to subtract the second AL from the first AL to get an AL of groups to which the user *isn't* assigned. Is
there an easy way to do this?

Thanks,

Craig

Nov 20 '05 #3

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

Similar topics

8
25358
by: dlx_son | last post by:
Here is the code so far <form name="thisform"> <h3>Enter time to add to or subtract from:</h3> (If not entered, current time will be used)<br> Day: <input name="d1" alt="Day of month"...
7
455
by: Alex Ting | last post by:
Hi Everybody, I have an issue about deleting an object from an arrayList. I've bounded a datagrid using this code where it will first run through all of the code in loadQuestions() and bind a...
3
2840
by: Stephen | last post by:
I was wondering if someone can help me with an web application design problem. I have a aspx page which builds up an arraylist called addresses and outputs the values in the arraylist items to a...
6
5375
by: gane kol | last post by:
Hi, I have a code that creates a datatable from an arraylist, but i am getting an error in casting in for (int intRow = 0; intRow < alLCPlist.Count; intRow++) { DataRow drow =...
4
347
by: Craig Buchanan | last post by:
I have two arraylists, one with a list of groups and one with a list of groups assigned to a user. I would like to subtract the second AL from the first AL to get an AL of groups to which the user...
4
2806
by: Peter | last post by:
I run into this situation all the time and I'm wondering what is the most efficient way to handle this issue: I'll be pulling data out of a data source and want to load the data into an array so...
18
4705
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the...
16
2730
by: Kittyhawk | last post by:
I would like to sort an Arraylist of objects on multiple properties. For instance, I have a Sort Index property and an ID property (both integers). So, the results of my sort would look like this:...
6
3125
by: fniles | last post by:
I am using VB.NET 2003 and a socket control to receive and sending data to clients. As I receive data in 1 thread, I put it into an arraylist, and then I remove the data from arraylist and send it...
3
2611
by: Christopher H | last post by:
I've been reading about how C# passes ArrayLists as reference and Structs as value, but I still can't get my program to work like I want it to. Simple example: ...
0
7225
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
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7383
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...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3194
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1557
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.