> For the complete documentation index, see [llms.txt](https://heunnajo.gitbook.io/java/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://heunnajo.gitbook.io/java/collection-framework/collections-framework.md).

# Collections framework

* **Collection**

\- 여러 객체(데이터)를 모아 놓은 것을 의미. 자바의 대표적인 자료구조.

* **Framework**\
  \- 표준화, 정형화된 체계적인 프로그래밍 방식
* **Collections framework**\
  \- 여러 객체를 정해진 방식대로 프로그래밍하는 것.\
  \- **컬렉션(다수의 객체)을 다루기 위한** **표준화된 프로그래밍 방식**\
  \- 컬렉션을 쉽고 편리하게 다룰 수 있는 다양한 클래스를 제공한다.(저장, 검색, 정렬, 삭제)&#x20;
* **Collection Class**\
  \- 다수의 데이터를 저장할 수 있는 클래스(ex, Vector, ArrayList, HashSet)
* **Core interface of collection framework**

![Core Interface of Collection Framework](https://513632279-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MHGT1oKZbTmlBrsOv_R%2F-MIXOgoAys5NtQ0FbnkM%2F-MIXbD9c5fZKavwTjSNb%2Fimage.png?alt=media\&token=0681280f-40c0-41a1-9151-aee521bcc274)

| Interface | Description                                                                                                                                                             |
| --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **List**  | <p>순서O, 중복O ex) 대기자 명단</p><p>=>ArrayList, LinkedList, Stack, Vector 등</p><p>순서 있는 데이터들 삽입(insert/addd), 삭제(remove/delete) 빈번하게 발생 : LinkedList, 아닐 경우 ArrayList 사용.</p> |
| **Set**   | <p>순서X, 중복X ex) 양의 정수집합, 소수의 집합</p><p>=>HashSet, TreeSet 등</p>                                                                                                          |
| **Map**   | <p>순서X, 중복 - 키 X, 값 O ex) 우편번호, 지역번호(전화번호)</p><p>=>HashMap, TreeMap, Hashtable, Properties 등</p>                                                                        |

추가적으로, 파일 자료구조도 있는데, 파일 구조는 순차파일, 색인파일, 직접파일이 있다.

* **Methods of Collection Interface** .&#x20;

| Method                                                                    | Description                                                                                                       |
| ------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| <p>boolean add(Object o)</p><p>boolean addAll(Collection c)</p>           | <p>추가.</p><p>지정된 객체(o) 또는 Collection(c)의 객체들을 Collection에 추가한다.</p>                                               |
| void clear()                                                              | <p>삭제.</p><p>Collection의 모든 객체를 삭제한다.</p>                                                                         |
| <p>boolean contains(Object o)</p><p>boolean containsAll(Collection c)</p> | <p>검색.</p><p>지정된 객체(o) 또는 Collection의 객체들이 Collection에 포함되어있는지 확인한다.</p>                                          |
| boolean equals(Object o)                                                  | <p>비교.</p><p>동일한 Collection인지 비교한다.</p>                                                                           |
| int hashCode()                                                            | Collection의 hash code를 반환한다.                                                                                      |
| boolean isEmpty()                                                         | Collection이 비어있는지 확인한다.                                                                                           |
| iterator iterator()                                                       | Collection의 iterator를 얻어서 반환한다.                                                                                   |
| boolean remove(Object o)                                                  | <p>삭제.</p><p>지정된 객체를 삭제한다.</p>                                                                                    |
| boolean removeAll(Collection c)                                           | 지정된 Collection에 포함된 객체들을 삭제한다.                                                                                    |
| boolean retainAll(Collection c)                                           | 지정된 Collection에 포함된 객체만을 남기고 다른 객체들은 Collection에서 삭제한다. 이 작업으로 인해 Collection에 변화가 있으면 true를, 그렇지 않으면 false를 반환한다. |
| int size()                                                                | Collection에 저장된 객체의 개수를 반환한다.                                                                                     |
| Object\[ ] toArray()                                                      | Collection에 저장된 객체를 객체배열(Object\[ ])로 반환한다.                                                                       |
| Object\[ ] toArray(Object\[ ] a)                                          | 지정된 배열에 Collection의 객체를 저장해서 반환한다.                                                                                |
