473,398 Members | 2,393 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,398 software developers and data experts.

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 2291
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
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
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
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
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
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
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
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
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
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
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
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.