컬렉션 프레임워크(Collections Framework) ?
컬렉션 프레임워크는 다수의 데이터를 저장, 구성 및 접근에 도움을 주는 인터페이스의 집합이고 여러 구현체들을 제공한다. 상황에 맞게 적절한 구현체를 사용할 수 있다.
컬렉션 프레임워크는 1998년 Java SE 2에 처음 도입되었으며 , 그 뒤로 Java SE 5에서 제네릭이 추가되었을 때, Java 8에서 람다 표현식과 인터페이스의 default 메소드가 추가되었을 때 두 번 추가로 작성되었다.
인터페이스 | 특징 | 구현 클래스 |
List | 순서가 있고, 중복을 허용한다. | ArrayList, LinkedList, Vector 등 |
Queue | 순서가 있고, 중복을 허용한다. FIFO 구조로 동작한다. | LinkedList, PriorityQueue 등 |
Deque | 순서가 있고, 중복을 허용한다. 양쪽에 데이터를 넣고 뺄 수 있는 형태의 자료구조이다. | ArrayDeque, LikedList 등 |
Set | 순서가 없고, 중복을 허용하지 않는다. | HashSet, TreeSet 등 |
Map | Key와 Value로 이루어진 데이터의 집합. 순서가 없고, Key는 중복을 허용하지 않고, Value는 중복을 허용한다. | HashMap, TreeMap 등 |
Iterable 과 Collection 인터페이스
Iterable
Iterable 인터페이스는 Java SE 5에 for each문, 제네릭과 함께 추가되었다.
인터페이스들의 공통인 메서드인 iterator(), forEach()를 뽑아서 중복을 제거하기 위한 것에 불과하므로 상속계층도에서 큰 의미가 없다.
- void forEach(Cosumer<? super T> action) : 모든 요소가 처리되거나 예외가 발생할 때까지 Iterable의 각 요소에 대해 지정된 작업을 수행한다.
- Iterator<t> iterator() : T 타입의 iterator를 리턴한다.
Collection
List와 Queue, Set의 조상이다.
add(), remove(), clear(), contains(), isEmpty(), size(), stream()등의 기본적인 메서드가 선언,정의되어 있다.
Collections 클래스
Collections 클래스는 Collection 인터페이스와 이름이 비슷하지만 Arrays와 마찬가지로 Collection을 다루기 위한 static 메서드들을 제공하는 클래스이다.
정렬, 병합, 빈 객체 생성, reverse, 이분탐색 알고리즘등 여러 기능이 구현되어있다.
https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/util/Collections.html
'Java' 카테고리의 다른 글
SpringBoot WebSocket 채팅기능 만들기 (2) - STOMP (0) | 2024.02.12 |
---|---|
SpringBoot WebSocket 채팅기능 만들기 (1) (1) | 2024.02.09 |
[Java] 람다 표현식 (0) | 2023.09.06 |
[Java] 동작 파라미터화 전달하기 (0) | 2023.08.31 |