473,569 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Easiest methods for copying and removing +elements+ of one ArrayList to/from another?

I have three Arraylists that hold strings corresponding to addresses of an
e-mail list:

ArrayList masterList
ArrayList optInToMasterLi st
ArrayList optOutFromMaste rList

I want to know the easiest way to add all of the +contents+ of one arraylist
to another.

masterList.Copy To (optInToMasterL ist) does not have the intended effect: I
end up with an array nested in an array, which is quite logical, but it
isn't what I want.

optInToMasterLi st.Remove(optOu tFromMasterList ) does not seem to work either.

I'm sure I could figure out how to .Add and .Remove what I want to using
looping structures, but I would be happiest if there's already an inbuilt
method in the Framework to help me out.

Can you help?

Thank you,
-KF
Nov 17 '06 #1
4 1442
Is this the sort of thing you are looking for?

ArrayList AL1 = new ArrayList(3);
ArrayList AL2 = new ArrayList(3);
ArrayList AL3 = new ArrayList(6);

//Fill an arraylist with strings
AL1.Add("One");
AL1.Add("Two");
AL1.Add("Three" );

//Fill another arraylist with strings
AL2.Add("Four") ;
AL2.Add("Five") ;
AL2.Add("Six");

//Combine the two arraylists into a third list
AL3.AddRange(AL 1);
AL3.AddRange(AL 2);

--
Cheers,
Gary
http://www.garyshort.org/

ke*****@nospam. nospam wrote:
I have three Arraylists that hold strings corresponding to addresses of an
e-mail list:

ArrayList masterList
ArrayList optInToMasterLi st
ArrayList optOutFromMaste rList

I want to know the easiest way to add all of the +contents+ of one arraylist
to another.

masterList.Copy To (optInToMasterL ist) does not have the intended effect: I
end up with an array nested in an array, which is quite logical, but it
isn't what I want.

optInToMasterLi st.Remove(optOu tFromMasterList ) does not seem to work either.

I'm sure I could figure out how to .Add and .Remove what I want to using
looping structures, but I would be happiest if there's already an inbuilt
method in the Framework to help me out.

Can you help?

Thank you,
-KF
Nov 17 '06 #2
Sometimes the brute force method will save you a lot of time, especially if
it doesn't involve a lot of code (pseudocode here):

for(int i=0;i<optIntoMa sterList.Length ;i++)
masterList.Add( optIntoMasterLi st[i]);

Cheers
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"ke*****@nospam .nospam" wrote:
I have three Arraylists that hold strings corresponding to addresses of an
e-mail list:

ArrayList masterList
ArrayList optInToMasterLi st
ArrayList optOutFromMaste rList

I want to know the easiest way to add all of the +contents+ of one arraylist
to another.

masterList.Copy To (optInToMasterL ist) does not have the intended effect: I
end up with an array nested in an array, which is quite logical, but it
isn't what I want.

optInToMasterLi st.Remove(optOu tFromMasterList ) does not seem to work either.

I'm sure I could figure out how to .Add and .Remove what I want to using
looping structures, but I would be happiest if there's already an inbuilt
method in the Framework to help me out.

Can you help?

Thank you,
-KF
Nov 17 '06 #3
Thanks to both of you. My application now works great and I know a lot more
about the ArrayLists's methods.

ArrayList newbies who discover this e-mail thread should note that the
ArrayList equivalent of the .Length property is ".Count".

-KF

"Peter Bromberg [C# MVP]" <pb*******@yaho o.nospammin.com wrote in message
news:75******** *************** ***********@mic rosoft.com...
Sometimes the brute force method will save you a lot of time, especially
if
it doesn't involve a lot of code (pseudocode here):

for(int i=0;i<optIntoMa sterList.Length ;i++)
masterList.Add( optIntoMasterLi st[i]);

Cheers
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"ke*****@nospam .nospam" wrote:
>I have three Arraylists that hold strings corresponding to addresses of
an
e-mail list:

ArrayList masterList
ArrayList optInToMasterLi st
ArrayList optOutFromMaste rList

I want to know the easiest way to add all of the +contents+ of one
arraylist
to another.

masterList.Cop yTo (optInToMasterL ist) does not have the intended effect:
I
end up with an array nested in an array, which is quite logical, but it
isn't what I want.

optInToMasterL ist.Remove(optO utFromMasterLis t) does not seem to work
either.

I'm sure I could figure out how to .Add and .Remove what I want to using
looping structures, but I would be happiest if there's already an inbuilt
method in the Framework to help me out.

Can you help?

Thank you,
-KF

Nov 17 '06 #4
Hi KF,

I agree with Peter. You can also use foreach statement for the loop.

Kevin Yu
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 20 '06 #5

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

Similar topics

99
5851
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less important changes, so in this thread I would like to focus on that issue alone. I have edited the Proposed Syntax example below to take out the...
24
4358
by: RyanTaylor | last post by:
I have a final coming up later this week in my beginning Java class and my prof has decided to give us possible Javascript code we may have to write. Problem is, we didn't really cover JS and what we covered was within the last week of the class and all self taught. Our prof gave us an example of a Java method used to remove elements from an...
3
1306
by: Nathan Sokalski | last post by:
I am having trouble removing cookies that I created with my site. Here is the code I am using to try and remove them: If Not Request.Cookies("username") Is Nothing Then Response.Cookies.Remove("username") If Not Request.Cookies("password") Is Nothing Then Response.Cookies.Remove("password")
7
1745
by: Adam Honek | last post by:
Is there a direct way to remove one entry from a one dimensional array? I keep looking but either my eyes are funny or it isn't there. Must we really create a temp array and copy all but 1 of the entries over to delete one entry? All I want to do is remove an entry at a specified index and then have the ubound(array) go down -1.
6
6093
by: Niyazi | last post by:
Hi all, What is fastest way removing duplicated value from string array using vb.net? Here is what currently I am doing but the the array contains over 16000 items. And it just do it in 10 or more minutes. 'REMOVE DUBLICATED VALUE FROM ARRAY +++++++++++++++++ Dim col As New Scripting.Dictionary Dim ii As Integer = 0
7
2629
by: David Lozzi | last post by:
Howdy, I have a shopping cart in my arraylist. Works great for adding items but I'm displaying the shopping cart in a gridview and the user can update the qty of the items. If they set it to 0, then I want to remove it. I'm doing the following script: For Each ele In bag Dim qty As Integer =...
9
3740
by: Jess | last post by:
Hello, I tried to clear a vector "v" using "v.clear()". If "v" contains those objects that are non-built-in (e.g. string), then "clear()" can indeed remove all contents. However, if "v" contains built-in types (e.g. int), then "clear()" doesn't remove anything at all. Why does "clear()" have this behaviour? Also, when I copy one...
2
2267
by: psbasha | last post by:
Hi, I am trying to assign the list elements(l1) to another list (l2).When I am trying to remove the element from l2,it is removing the element from l1. Is there any method available to copy the list elements?So that I can avoid deleting the elements. Sample >>> l1 = >>> l2 = l1 >>> l2.remove(3)
6
1902
by: Curious | last post by:
I have an arraylist used in three separate methods. In method #1 (event method), some items are removed from the arraylist if certain conditions are met; In method #2 (event method), properties of some items are modified if certain conditions are met; In method #3, it loops through each item in the arraylist without changing any item...
0
7694
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7609
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8118
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6278
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5504
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2107
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 we have to send another system
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.