int [] exp = new int[5] {1,2,3,4,5};
// 컬렉션 : 리스트, 큐, 스택, 해시테이블, 딕셔너리, 어레이리스트
- ArrayList
ArrayList arrayList = new ArrayList();
arrayList.Add(1);
arrayList.Add("가나다");
arrayList.Add(2);
arrayList.Remove("가나다");
arrayList.RemoveAt(0); // 인덱스 번호
arrayList.RemoveRange(0,1);
arrayList.Clear(); // 초기화 -> 전부 삭제
arrayList.Contains("가나다라") // 특정 값이 있는지 확인
for ( int i = 0 ; i < arrayList.Count ; i++ )
{
print(arrayList[i]);
}
- List
List<int> list = new List<int>();
//arraylist와 list의 차이 -> list는 특정 자료형을 가진 값만 추가 가능하다.
- Hashtable
Hashtable hashTable = new Hashtable();
hashTable.Add("만", 10000);
hashTable.Add("백만", 1000000);
print(hashTable["만"]); //키 값으로 접근해야한다.
- Dictionary
// Dictionary와 hashtable의 차이는 arraylist와 list 처럼 자료형을 명시해주는 차이가 난다.
Dictionary<string, int> dictionary = new Dictionary<string, int>();
dictionary.Add("가",100);
- Queue (선입선출, FIFO)
Queue<int> queue = new Queue<int>();
queue.Enqueue(5);
queue.Enqueue(10);
// if(queue.Conut != 0)
print(queue.Dequeue());
print(queue.Dequeue());
- Stack (후입선출, LIFO)
Stack<int> stack = new Stack<int>();
stack.Push(1);
stack.Push(2);
stack.Push(3);
print(stack.Pop());
print(stack.Pop());