Create a fixed-size wrapper around an ArrayList. : List « Data Structure « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Data Structure » ListScreenshots 
Create a fixed-size wrapper around an ArrayList.
  

Imports System
Imports System.Collections
Imports Microsoft.VisualBasic

Public Class SamplesArrayList    
    Public Shared Sub Main()
        Dim myAL As New ArrayList()
        myAL.Add("The")
        myAL.Add("quick")
        myAL.Add("brown")
        myAL.Add("fox")

        Dim myFixedSizeAL As ArrayList = ArrayList.FixedSize(myAL)

        Dim msg As String
        If myAL.IsFixedSize Then
            msg = "has a fixed size"
        Else
            msg = "does not have a fixed size"
        End If

        PrintValues(myAL, " "c)
        PrintValues(myFixedSizeAL, " "c)

        myFixedSizeAL.Sort()

        PrintValues(myAL, " "c)
        PrintValues(myFixedSizeAL, " "c)

        myFixedSizeAL.Reverse()

        PrintValues(myAL, " "c)
        PrintValues(myFixedSizeAL, " "c)

        myAL.Add("AddMe")

        PrintValues(myAL, " "c)
        PrintValues(myFixedSizeAL, " "c)

        Try
            myFixedSizeAL.Add("AddMe2")
        Catch myException As Exception
            Console.WriteLine("Exception: " + myException.ToString())
        End Try
        Try
            myFixedSizeAL.Insert(3"InsertMe")
        Catch myException As Exception
            Console.WriteLine("Exception: " + myException.ToString())
        End Try
    End Sub 'Main

    Public Shared Sub PrintValues(myList As IEnumerable, mySeparator As Char)
        Dim obj As [Object]
        For Each obj In  myList
            Console.Write("{0}{1}", mySeparator, obj)
        Next obj
        Console.WriteLine()
    End Sub 'PrintValues

End Class

   
    
  
Related examples in the same category
1.List Range operation
2.Check the List.Capacity before and after adding elements
3.Does List contain a certain element
4.Add element to List at position of 2
5.Remove an element from List
6.Trim down extra capacity from List
7.Clear a List
8.Using a BindingSource component to bind a list to a DataGridView control
9.Uses a cursor to step through the message queues and list the public queues on the network.
10.Using Order By to sort a list of words alphabetically
11.Using Order By to sort a list of words by length
12.Using Group By to partition a list of words by first letter
13.Converting ToList
14.Using a Where clause to find all projectList that are in stock and cost more than 3.00 per unit
15.Using Take to get the first 3 orders from employeeList
16.Using Payment By to sort a list of projectList by units in stock from highest to lowest
17.Using Except to do minus between two lists
18.Use Action<(Of <(T>)>) delegate to print the contents of a List<(Of <(T>)>) object.
19.List the Unicode code point of each of the control characters.
20.Create a SortedList using the default comparer.
21.Create a SortedList using the specified case-insensitive comparer.
22.Create a SortedList using the specified CaseInsensitiveComparer,
23.Create a SortedList using the StringComparer.InvariantCultureIgnoreCase value.
24.Implements a TextWriterTraceListener named myWriter to write to the console screen.
25.All three overloads of the CopyTo method in List<(Of <(T>)>)
26.Synchronize an ArrayList, determine if an ArrayList is synchronized and use a synchronized ArrayList.
27.LinkedListNode<(Of <(T>)>), adds it to a LinkedList<(Of <(T>)>), tracks values of its properties as the LinkedList<(Of <(T>)>) changes.
28.What is the different between the Count and Capacity
29.Get the fourth element
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.