How to Insert element at the beginning of ArrayList in VB.NET

1 Answer

0 votes
Imports System
Imports System.Collections

Public Class Program
    Public Shared Sub PrintArrayList(ByVal list As ArrayList)
        For Each e In list
            Console.WriteLine(e)
        Next
    End Sub

    Public Shared Sub Main()
        Dim al As ArrayList = New ArrayList()
        al.Add("java")
        al.Add("c#")
        al.Add("python")
        al.Add("c")
        al.Add("php")
        PrintArrayList(al)
	
        al.Insert(0, "c++")
        Console.WriteLine()
        PrintArrayList(al)
    End Sub
End Class



' run:
'
' java
' c#
' python
' c
' php
' 
' c++
' java
' c#
' python
' c
' php
' 
'

 



answered Feb 19, 2025 by avibootz

Related questions

1 answer 160 views
1 answer 88 views
2 answers 180 views
1 answer 257 views
1 answer 194 views
2 answers 227 views
1 answer 147 views
...