Solved

Adding arrays

Posted on 2009-04-12
14
189 Views
Last Modified: 2013-11-26
How can I add two arraylist togther to make a single arraylist. I have an array list of 1240 reading and I want to add the second array that has 6 arraylist reading to the front end, how can I do this

Dim array1 as New arraylist
Dim array2 as new arraylist


0
Comment
Question by:cmdolcet
  • 6
  • 5
  • 3
14 Comments
 
LVL 48

Expert Comment

by:jpaulino
ID: 24127292
You can use AddRange to add the array1 into array2

array2.AddRange(array1)
0
 

Author Comment

by:cmdolcet
ID: 24127392
what if i wanted to put arraylist in the upper 6  of arraylist 1 total 1240 and the bottom 6

0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24127396
You can use InsertRange where you can define where to insert

array2.InsertRange(0, array1)
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24127398
0 is the position (index)
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 24127401
I think you'd have to iterate over array2 and use the Insert() command:

        For i As Integer = 0 To array2.Count - 1
            array1.Insert(i, array2(i))
        Next
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 24127409
Haha...InsertRange() is better...silly Intellisense!

0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 24127412
(and silly Idle_Mind)
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 48

Expert Comment

by:jpaulino
ID: 24127432
LOL,
Idle_Mind you have to select the Intellisense to show all the available properties and methods and not only the common ones :)
0
 

Author Comment

by:cmdolcet
ID: 24127442
ok so if i understand this correctly then
array2.InsertRange(0, array1) would insert the second array onto the top of the first therefore this code would only work if i insert the second array on the top of the forst array. but lets say i wanted to insert the second array on the bottom i would use the following code
array2.InsertRange(1240, array1)

correct?
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24127449
If you can insert at the bottom you can use AddRange:
array2.AddRange(array1)
 
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 24127456
If you want to add array2 into array1 then you need to call the methods against array1:

    array1.InsertRange(0, array2) ' <-- add array2 to the top of array1

    array1.AddRange(array2) ' <-- add array2 to the bottom of array1
0
 

Author Comment

by:cmdolcet
ID: 24127464
no lets say i want to not add the array 2 to the top but now the bottom how can i do that?

The overall idea is having 3 arraylist, arraylist 1 would be the master array i want to add arraylist 2 to the top of arraylist1 and arrayllist 3 to the bottom of arraylist 1

se the visual pic would be this
arraylist2
arraylist1
arraylist3

I hope this helps sorry for being so confusing :)
0
 
LVL 48

Accepted Solution

by:
jpaulino earned 250 total points
ID: 24127467
Should be this way then to have all values in the array1

array1.InsertRange(0, array2)

array1.AddRange(array3)

Open in new window

0
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 250 total points
ID: 24127473
That would be:

    array1.InsertRange(0, array2) ' <-- add array2 to the top of array1
    array1.AddRange(array3) ' <-- add array3 to the bottom of array1

(assuming that you want to change the contents of array1)

If you want to keep all the arraylists intact, then create a new one:

    Dim array4 As New ArrayList
    array4.AddRange(array2)
    array4.AddRange(array1)
    array4.AddRange(array3)
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now