Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Don't use ArrayList!

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.

like image 900
Voldemort Avatar asked Jan 28 '11 00:01

Voldemort


People also ask

Why do we need to type ArrayList instead of array?

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 [].

What is ArrayList in Java?

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 ...

What is the difference between a built-in array and an ArrayList?

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:

Why are arraylists so slow?

'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.


1 Answers

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).

like image 63
Alxandr Avatar answered Sep 24 '22 07:09

Alxandr