Resizing an arraylist

C

cmdolcet69

I have an arraylist of for example 1200. I want to re organize the
array so that position 1 on the arraylist if actaully now position 3
and i want to add 3 position before position 3 and at the end of the
arraylist. Can i use the Redim statement?
 
A

Armin Zingler

cmdolcet69 said:
I have an arraylist of for example 1200. I want to re organize the
array so that position 1 on the arraylist if actaully now position 3
and i want to add 3 position before position 3 and at the end of the
arraylist. Can i use the Redim statement?

The benefit in using an Arraylist is that you do _not_ have to (and
can't) ReDim anything. Use the Add/Insert/Remove/RemoveAt methods to
add/remove items. In VB 2005 and above, there are several additional
Generic lists, like List(Of T).


Armin
 
C

cmdolcet69

The benefit in using an Arraylist is that you do _not_ have to (and
can't) ReDim anything. Use the Add/Insert/Remove/RemoveAt methods to
add/remove items. In VB 2005 and above, there are several additional
Generic lists, like List(Of T).

Armin

How can i add in 3 position at the start???
 
H

Herfried K. Wagner [MVP]

cmdolcet69 said:
The benefit in using an Arraylist is that you do _not_ have to (and
can't) ReDim anything. Use the Add/Insert/Remove/RemoveAt methods to
add/remove items. In VB 2005 and above, there are several additional
Generic lists, like List(Of T).

How can i add in 3 position at the start???

Take a look at 'ArrayList.Insert'.
 
S

SurturZ

I think this is what you are after:

Module Module1
Sub Main()
Dim arl As New ArrayList
'initialise
arl.Add(0)
arl.Add(1)
arl.Add(2)
arl.Add(3)
arl.Add(4)
arl.Add(5)
'move first two elements to the end
arl.Add(arl(0))
arl.RemoveAt(0)
arl.Add(arl(0))
arl.RemoveAt(0)

For Each o As Object In arl
Console.Write(o.ToString & " ")
Next
Console.ReadKey()

End Sub

End Module
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top