ArrayList 클래스

정의

필요에 따라 크기가 동적으로 증가하는 배열을 사용하여 IList 인터페이스를 구현합니다.

public ref class ArrayList : System::Collections::IList
public ref class ArrayList : ICloneable, System::Collections::IList
public class ArrayList : System.Collections.IList
public class ArrayList : ICloneable, System.Collections.IList
[System.Serializable]
public class ArrayList : ICloneable, System.Collections.IList
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class ArrayList : ICloneable, System.Collections.IList
type ArrayList = class
    interface IEnumerable
    interface IList
    interface ICollection
type ArrayList = class
    interface ICollection
    interface IEnumerable
    interface IList
    interface ICloneable
type ArrayList = class
    interface IEnumerable
    interface IList
    interface ICollection
    interface ICloneable
[<System.Serializable>]
type ArrayList = class
    interface IList
    interface ICollection
    interface IEnumerable
    interface ICloneable
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type ArrayList = class
    interface IList
    interface ICollection
    interface IEnumerable
    interface ICloneable
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type ArrayList = class
    interface IList
    interface ICloneable
    interface ICollection
    interface IEnumerable
Public Class ArrayList
Implements IList
Public Class ArrayList
Implements ICloneable, IList
상속
ArrayList
파생
특성
구현

예제

다음 예제에서는 만들고 초기화 ArrayList 하는 방법 및 해당 값을 표시 하는 방법을 보여 주는 합니다.

using namespace System;
using namespace System::Collections;
void PrintValues( IEnumerable^ myList );
int main()
{
   
   // Creates and initializes a new ArrayList.
   ArrayList^ myAL = gcnew ArrayList;
   myAL->Add( "Hello" );
   myAL->Add( "World" );
   myAL->Add( "!" );
   
   // Displays the properties and values of the ArrayList.
   Console::WriteLine( "myAL" );
   Console::WriteLine( "    Count:    {0}", myAL->Count );
   Console::WriteLine( "    Capacity: {0}", myAL->Capacity );
   Console::Write( "    Values:" );
   PrintValues( myAL );
}

void PrintValues( IEnumerable^ myList )
{
   IEnumerator^ myEnum = myList->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      Object^ obj = safe_cast<Object^>(myEnum->Current);
      Console::Write( "   {0}", obj );
   }

   Console::WriteLine();
}

/* 
This code produces output similar to the following:

myAL
    Count:    3
    Capacity: 4
    Values:   Hello   World   !

*/
using System;
using System.Collections;
public class SamplesArrayList  {

   public static void Main()  {

      // Creates and initializes a new ArrayList.
      ArrayList myAL = new ArrayList();
      myAL.Add("Hello");
      myAL.Add("World");
      myAL.Add("!");

      // Displays the properties and values of the ArrayList.
      Console.WriteLine( "myAL" );
      Console.WriteLine( "    Count:    {0}", myAL.Count );
      Console.WriteLine( "    Capacity: {0}", myAL.Capacity );
      Console.Write( "    Values:" );
      PrintValues( myAL );
   }

   public static void PrintValues( IEnumerable myList )  {
      foreach ( Object obj in myList )
         Console.Write( "   {0}", obj );
      Console.WriteLine();
   }
}


/*
This code produces output similar to the following:

myAL
    Count:    3
    Capacity: 4
    Values:   Hello   World   !

*/
Imports System.Collections

Public Class SamplesArrayList    
    
    Public Shared Sub Main()
        
        ' Creates and initializes a new ArrayList.
        Dim myAL As New ArrayList()
        myAL.Add("Hello")
        myAL.Add("World")
        myAL.Add("!")
        
        ' Displays the properties and values of the ArrayList.
        Console.WriteLine("myAL")
        Console.WriteLine("    Count:    {0}", myAL.Count)
        Console.WriteLine("    Capacity: {0}", myAL.Capacity)
        Console.Write("    Values:")
        PrintValues(myAL)
    End Sub

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

End Class


' This code produces output similar to the following:
' 
' myAL
'     Count:    3
'     Capacity: 4
'     Values:   Hello   World   !

설명

중요

새 개발에 클래스를 ArrayList 사용하지 않는 것이 좋습니다. 대신 제네릭 List<T> 클래스를 사용하는 것이 좋습니다. 클래스는 ArrayList 다른 유형의 개체 컬렉션을 보유하도록 설계되었습니다. 그러나 항상 최상의 성능을 제공하는 것은 아닙니다. 대신 다음을 권장합니다.

  • 다른 유형의 개체 컬렉션의 경우 (C#) 또는 List(Of Object) (Visual Basic의 경우) 형식을 사용합니다 List<Object> .
  • 동일한 개체 컬렉션의 경우 클래스를 List<T> 사용합니다.
    이러한 클래스의 상대적 성능에 List<T> 대한 자세한 내용은 참조 항목의 성능 고려 사항을 참조하세요. 제네릭이 아닌 컬렉션 형식 대신 제네릭 사용에 대한 일반적인 정보는 GitHub에서 제네릭이 아닌 컬렉션을 사용하면 안 됨을 참조하세요.

ArrayList 정렬되도록 보장되지 않습니다. 를 정렬해야 하는 작업(예: BinarySearch)을 수행하기 전에 메서드 ArrayList 를 호출 Sort 하여 를 정렬 ArrayList 해야 합니다. 새 요소가 추가될 때 자동으로 정렬되는 컬렉션을 유지 관리하려면 클래스를 SortedSet<T> 사용할 수 있습니다.

ArrayList 용량은 가 보유할 수 있는 ArrayList 요소의 수입니다. 요소가 에 ArrayList추가되면 재할당을 통해 필요에 따라 용량이 자동으로 증가합니다. 를 호출 TrimToSize 하거나 속성을 명시적으로 설정하여 용량을 Capacity 줄일 수 있습니다.

.NET Framework 전용: 매우 큰 ArrayList 개체의 경우 런타임 환경에서 구성 요소의 <gcAllowVeryLargeObjects> 특성을 로 설정 enabled 하여 64비트 시스템에서 최대 용량을 20억 요소로 true 늘릴 수 있습니다.

이 컬렉션의 요소는 정수 인덱스로 액세스할 수 있습니다. 이 컬렉션의 인덱스는 0부터 시작 합니다.

컬렉션은 ArrayList 유효한 값으로 허용됩니다 null . 또한 중복 요소를 허용합니다.

다차원 배열을 컬렉션의 ArrayList 요소로 사용하는 것은 지원되지 않습니다.

생성자

ArrayList()

비어 있는 상태에서 기본 초기 용량을 가지는 ArrayList 클래스의 새 인스턴스를 초기화합니다.

ArrayList(ICollection)

지정한 컬렉션에서 복사된 요소가 포함되어 있고 복사된 요소의 수와 같은 초기 용량을 가지는 ArrayList 클래스의 새 인스턴스를 초기화합니다.

ArrayList(Int32)

비어 있는 상태에서 지정한 초기 용량을 가지는 ArrayList 클래스의 새 인스턴스를 초기화합니다.

속성

Capacity

ArrayList에 포함될 수 있는 요소의 수를 가져오거나 설정합니다.

Count

ArrayList에 실제로 포함된 요소의 수를 가져옵니다.

IsFixedSize

ArrayList의 크기가 고정되어 있는지 여부를 나타내는 값을 가져옵니다.

IsReadOnly

ArrayList가 읽기 전용인지 여부를 나타내는 값을 가져옵니다.

IsSynchronized

ArrayList에 대한 액세스가 동기화되어 스레드로부터 안전하게 보호되는지를 나타내는 값을 가져옵니다.

Item[Int32]

지정한 인덱스에 있는 요소를 가져오거나 설정합니다.

SyncRoot

ArrayList에 대한 액세스를 동기화하는 데 사용할 수 있는 개체를 가져옵니다.

메서드

Adapter(IList)

특정 IList에 대해 ArrayList 래퍼를 만듭니다.

Add(Object)

개체를 ArrayList의 끝 부분에 추가합니다.

AddRange(ICollection)

ICollection의 요소를 ArrayList의 끝에 추가합니다.

BinarySearch(Int32, Int32, Object, IComparer)

지정된 비교자를 사용하여 정렬된 ArrayList의 요소 범위에서 요소를 검색하고 요소의 인덱스(0부터 시작)를 반환합니다.

BinarySearch(Object)

기본 비교자를 사용하여 정렬된 전체 ArrayList에서 요소를 검색하고 요소의 인덱스(0부터 시작)를 반환합니다.

BinarySearch(Object, IComparer)

지정된 비교자를 사용하여 정렬된 전체 ArrayList에서 요소를 검색하고 요소의 인덱스(0부터 시작)를 반환합니다.

Clear()

ArrayList에서 요소를 모두 제거합니다.

Clone()

ArrayList의 부분 복사본을 만듭니다.

Contains(Object)

ArrayList에 요소가 있는지 여부를 확인합니다.

CopyTo(Array)

대상 배열의 맨 처음부터 시작하여 전체 ArrayList를 호환되는 1차원 Array에 복사합니다.

CopyTo(Array, Int32)

대상 배열의 지정된 인덱스에서 시작하여 전체 ArrayList을 호환되는 1차원 Array에 복사합니다.

CopyTo(Int32, Array, Int32, Int32)

대상 배열의 지정한 인덱스에서 시작하여 ArrayList의 요소 범위를 호환되는 1차원 Array에 복사합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
FixedSize(ArrayList)

고정 크기의 ArrayList 래퍼를 반환합니다.

FixedSize(IList)

고정 크기의 IList 래퍼를 반환합니다.

GetEnumerator()

전체 ArrayList에 대한 열거자를 반환합니다.

GetEnumerator(Int32, Int32)

ArrayList의 요소 범위에 대한 열거자를 반환합니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetRange(Int32, Int32)

소스 ArrayList에서 요소의 하위 집합을 나타내는 ArrayList를 반환합니다.

GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
IndexOf(Object)

지정한 Object를 검색하고, 전체 ArrayList 내에서 처음 나오는 0부터 시작하는 인덱스를 반환합니다.

IndexOf(Object, Int32)

지정된 Object를 검색하고, 지정된 인덱스부터 마지막 요소까지 포함되는 ArrayList의 요소 범위에서 처음 나오는 0부터 시작하는 인덱스를 반환합니다.

IndexOf(Object, Int32, Int32)

지정된 Object를 검색하고, 지정된 인덱스부터 시작하여 지정된 수의 요소를 포함하는 ArrayList의 요소 범위에서 처음 나오는 0부터 시작하는 인덱스를 반환합니다.

Insert(Int32, Object)

ArrayList의 지정된 인덱스에 요소를 삽입합니다.

InsertRange(Int32, ICollection)

ArrayList의 지정된 인덱스에 컬렉션의 요소를 삽입합니다.

LastIndexOf(Object)

지정한 Object 검색하고, 전체 ArrayList 내에서 마지막으로 검색된 항목의 0부터 시작하는 인덱스를 반환합니다.

LastIndexOf(Object, Int32)

지정된 Object를 검색하고, 첫 번째 요소부터 지정된 인덱스까지 확장되는 ArrayList의 요소 범위에서 마지막으로 검색된 항목의 0부터 시작하는 인덱스를 반환합니다.

LastIndexOf(Object, Int32, Int32)

지정된 Object를 검색하며, 지정된 수의 요소를 포함하고 지정된 인덱스에서 끝나는 ArrayList의 요소 범위에서 마지막으로 검색되는 0부터 시작하는 인덱스를 반환합니다.

MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ReadOnly(ArrayList)

읽기 전용 ArrayList 래퍼를 반환합니다.

ReadOnly(IList)

읽기 전용 IList 래퍼를 반환합니다.

Remove(Object)

ArrayList에서 맨 처음 발견되는 특정 개체를 제거합니다.

RemoveAt(Int32)

ArrayList의 지정된 인덱스에 있는 요소를 제거합니다.

RemoveRange(Int32, Int32)

ArrayList에서 요소의 범위를 제거합니다.

Repeat(Object, Int32)

요소가 지정된 값의 복사본인 ArrayList를 반환합니다.

Reverse()

전체 ArrayList에서 요소의 순서를 반대로 바꿉니다.

Reverse(Int32, Int32)

지정된 범위에서 요소의 순서를 반대로 바꿉니다.

SetRange(Int32, ICollection)

ArrayList의 요소 범위에 대해 컬렉션의 요소를 복사합니다.

Sort()

전체 ArrayList의 요소를 정렬합니다.

Sort(IComparer)

지정된 비교자를 사용하여 전체 ArrayList에 있는 요소를 정렬합니다.

Sort(Int32, Int32, IComparer)

지정된 비교자를 사용하여 ArrayList의 요소 범위에 있는 요소를 정렬합니다.

Synchronized(ArrayList)

동기화되어 스레드로부터 안전하게 보호되는 ArrayList 래퍼를 반환합니다.

Synchronized(IList)

동기화되어 스레드로부터 안전하게 보호되는 IList 래퍼를 반환합니다.

ToArray()

ArrayList의 요소를 새 Object 배열에 복사합니다.

ToArray(Type)

ArrayList의 요소를 지정된 요소 형식의 새 배열에 복사합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)
TrimToSize()

용량을 ArrayList의 실제 요소 수로 설정합니다.

확장 메서드

Cast<TResult>(IEnumerable)

IEnumerable의 요소를 지정된 형식으로 캐스팅합니다.

OfType<TResult>(IEnumerable)

지정된 형식에 따라 IEnumerable의 요소를 필터링합니다.

AsParallel(IEnumerable)

쿼리를 병렬화할 수 있도록 합니다.

AsQueryable(IEnumerable)

IEnumerableIQueryable로 변환합니다.

적용 대상

스레드 보안

공용 정적 (Shared Visual Basic의)이 형식의 멤버는 스레드로부터 안전 합니다. 인스턴스 구성원은 스레드로부터의 안전성이 보장되지 않습니다.

ArrayList 지원할 수 있습니다 여러 판독기 동시에 따라 컬렉션을 수정 되지 않습니다. 의 ArrayList스레드 안전을 보장하려면 메서드에서 반환 Synchronized(IList) 된 래퍼를 통해 모든 작업을 수행해야 합니다.

컬렉션 전체를 열거하는 프로시저는 기본적으로 스레드로부터 안전하지 않습니다. 컬렉션이 동기화되어 있을 때 다른 스레드에서 해당 컬렉션을 수정할 수 있으므로 이렇게 되면 열거자에서 예외가 throw됩니다. 열거하는 동안 스레드로부터 안전을 보장하려면 전체 열거를 수행하는 동안 컬렉션을 잠그거나 다른 스레드에서 변경된 내용으로 인해 발생한 예외를 catch하면 됩니다.

추가 정보