People often tell me not to use ArrayList for making my arrays in VB.NET. I would like to hear opinions about that, why shouldn't I? What is the best method for creating and manipulating array contents, dimensions etc?
Thanks.
From the side indicators we can see that Array implemements the same interfaces as ArrayList, but has a few more as well. This is because Array is a generic class that needs to be typed, as we did during the last post when creating specifically typed arrays, or what PowerShell does for us when creating an Object [].
Java ArrayList. The ArrayList class is a resizable array, which can be found in the java.util package. The difference between a built-in array and an ArrayList in Java, is that the size of an array cannot be modified (if you want to add or remove elements to/from an array, you have to create a new one). While elements can be added and removed ...
The difference between a built-in array and an ArrayList in Java, is that the size of an array cannot be modified (if you want to add or remove elements to/from an array, you have to create a new one). While elements can be added and removed from an ArrayList whenever you want. The syntax is also slightly different:
'Don’t Use ArrayLists!' Last time we took a look at the most basic type of collection in PowerShell, and explored how we could specify exactly what type of array we wanted. It turned out that arrays are extremely slow when modifying size, as they are actually static structures that need to be re-created every time we add an element.
Use generic lists instead. ArrayList is not typed, meaning that you can have a list with strings, numbers, +++. Rather you should use a generic list like this:
Dim list1 As New List(Of String) ' This beeing a list of string
The lists-class also allows you to expand the list on the fly, however, it also enforces typing which helps write cleaner code (you don't have to typecast) and code that is less prone to bugs.
ArrayList is gennerally speaking just a List(Of Object)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With