Instantiating lists
Like other data structures, lists must be defined and instantiated prior to being used. Each of the four languages that we will examine in this text has varying support for, and unique implementations of, the list data structure. Let's briefly examine how to instantiate a list in each language.
C#
Instantiating lists in C# requires the use of the new
keyword:
//Array backed lists ArrayList myArrayList = new ArrayList(); List<string> myOtherArrayList = new List<string>(); //Linked lists LinkedList<string> myLinkedList = new LinkedList<string>();
The C# ArrayList
class originated in .NET 1.0, and it is not used very often anymore. Most developers prefer to use the generic concrete implementation, List<of T>
, for an array-based list. This is also true for the generic concrete linked list implementation, LinkedList<of T>
. There is no non-generic linked list data structure in C#.
Java
Like C#, initializing...