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

Merge the contents of one arraylist into another.

I have a function that returns an arraylist.

I want the returned arraylist to be copied into the local arraylist.
What is the most efficient way of doing this?

-Peter

Nov 21 '05 #1
11 16409
"pmclinn" <pe***@mclinn.com> schrieb:
I want the returned arraylist to be copied into the local arraylist.
What is the most efficient way of doing this?


Assuming 'al1' and 'al2' are variables pointing to different arraylists, and
'al2''s content should be added to 'al1':

\\\
al1.AddRange(al2)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2
Hi Peter,

is the array list you return already filled? or is it an empty one, if it's
empty you can do it like this

Private Sub button1_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles button1.Click
Dim arr As New ArrayList
arr = GiveArraylist()
For i As Integer = 0 To arr.Count - 1
MsgBox(arr(i))
Next
End Sub

Private Function GiveArraylist() As ArrayList
Dim arr As New ArrayList
arr.Add("value1")
arr.Add("value2")
arr.Add("value3")
Return arr
End Function

hth Peter
"pmclinn" <pe***@mclinn.com> wrote in message
news:11*********************@c13g2000cwb.googlegro ups.com...
I have a function that returns an arraylist.

I want the returned arraylist to be copied into the local arraylist.
What is the most efficient way of doing this?

-Peter

Nov 21 '05 #3
Just use arrayList.Add. There is an overload that takes another arraylist.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"pmclinn" <pe***@mclinn.com> wrote in message
news:11*********************@c13g2000cwb.googlegro ups.com...
I have a function that returns an arraylist.

I want the returned arraylist to be copied into the local arraylist.
What is the most efficient way of doing this?

-Peter

Nov 21 '05 #4
Bob,

"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> schrieb:
Just use arrayList.Add. There is an overload that takes another arraylist.


Are you sure about this? I don't see this overload for .NET 1.1.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #5
OOPs.. Red herring..Wrong API.

You need to use AddRange.

private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs
e)

{

ArrayList a=new ArrayList();

ArrayList b=new ArrayList();

a.Add("One");

a.Add("Two");

a.Add("Three");

a.Add("Four");

a.Add("Five");

b.Add("Six");

b.Add("Seven");

b.Add("Eight");

b.Add("Nine");

b.Add("Ten");

a.AddRange(b);

int y=10;

foreach(string s in a)

{

e.Graphics.DrawString(s,Font,Brushes.Black,10,y);

y+=(int)Font.GetHeight()+4;

}
--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"pmclinn" <pe***@mclinn.com> wrote in message
news:11*********************@c13g2000cwb.googlegro ups.com...
I have a function that returns an arraylist.

I want the returned arraylist to be copied into the local arraylist.
What is the most efficient way of doing this?

-Peter

Nov 21 '05 #6
Brain fade on my part. Sorry.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uF**************@tk2msftngp13.phx.gbl...
Bob,

"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> schrieb:
Just use arrayList.Add. There is an overload that takes another
arraylist.


Are you sure about this? I don't see this overload for .NET 1.1.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #7
Bob,

"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> schrieb:
OOPs.. Red herring..Wrong API.

You need to use AddRange.


Wrong programming language now :-))).

SCNR

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #8
You can tell I'm having a bad day can't you :-(

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:ud**************@TK2MSFTNGP09.phx.gbl...
Bob,

"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> schrieb:
OOPs.. Red herring..Wrong API.

You need to use AddRange.


Wrong programming language now :-))).

SCNR

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #9
>> I want the returned arraylist to be copied into the local arraylist.
What is the most efficient way of doing this?


Assuming 'al1' and 'al2' are variables pointing to different arraylists,
and 'al2''s content should be added to 'al1':

\\\
al1.AddRange(al2)
///

Are you sure this method is "copying", I have another idea (for copying I
am used to talk about values not references)

Cor
Nov 21 '05 #10
Cor,

"Cor Ligthert" <no************@planet.nl> schrieb:
I want the returned arraylist to be copied into the local arraylist.
What is the most efficient way of doing this?


Assuming 'al1' and 'al2' are variables pointing to different arraylists,
and 'al2''s content should be added to 'al1':

\\\
al1.AddRange(al2)
///

Are you sure this method is "copying", I have another idea (for copying I
am used to talk about values not references)


It will copy the references stored in the arraylist referenced by 'al2' into
the arraylist referenced by 'al1'. So, even references can be "copied", not
only values, which rarely makes sense.

| Subject: Merge the contents of one arraylist into another.

.... which is what my code does.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #11
Herfried,
... which is what my code does.

I am glad you explain that to me.

Here a nice copy of a reference

http://www.rainews24.rai.it/ran24/sp...o/foto/100.jpg

Thank you very much.

:-)

Cor

Nov 21 '05 #12

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

Similar topics

2
by: Tommy | last post by:
Is it possible for a webpage to update itself based on what is present on another page. By this I mean that if the contents of page #2 is changed, then page #1 will load with the new information...
3
by: Deborah V. Gardner | last post by:
I would like to use conditional formatting on a subform and have 2 textbox affected. ItemID Qty Cost OrderDate 123 1 10.00 3/3/05 345 ...
3
by: VM | last post by:
How can I copy the contents of one datatable to another datatable? I've already the source table so I only need to copy its rows. Thanks.
1
by: VMI | last post by:
How can I copy the contents of a directory without having to 1) create dir, 2)copy files ,etc...? Thanks.
2
by: Jedi10180 | last post by:
I have a combo box that has 5 categories in it. When a user clicks on a category in that list, I need to have a second box populate with a list of pdf files that relate only to that category. Then,...
7
by: MN | last post by:
I am using a program called IDWorks which is reading and writing to an MS Access format database. The IDWorks program can't adjust the formatting on a displayed field in a way that we need so I...
8
by: toton | last post by:
Hi, I am facing problem some times, and not finding a suitable answer to solve it. I have a vector (or some other container, sometimes) of some class, named CC like vector<CCv, NOT vector<CC*; ...
1
LacrosseB0ss
by: LacrosseB0ss | last post by:
Hey folks; I have 2 forms (form1 and form2). Form2 is a print view of Form1. The user fills out form1 (textboxes and such) and submits to Form2 for reviewing/printing before submitting to a...
1
by: rency | last post by:
hi friends, Please give me solution if u have..it is very urgent for me! i have folders as a |....a1 |...... |...test.txt |
0
by: David Brey | last post by:
I am in the process of creating a database in Access 2007 to manage changes to products. I am a fairly new use of Access and would appreciate your help in solving my problem. I am going to use my...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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.