본문 바로가기

자료구조9

[자료구조] Hash Set - 입력한 순서가 보장되지 않는다. - 중복된 값을 허용하지 않는다. - NULL 삽입이 가능하다. 생성 import java.util.HashSet; HashSet colors1 = new HashSet(); // 타입 지정 HashSet colors2 = new HashSet(); // 타입 생략 가능 HashSet colors3 = new HashSet(10); // 초기 용량(Capacity) 설정 HashSet colors4 = new HashSet(colors1); // 다른 Collection값으로 초기화 HashSet colors5 = new HashSet(Arrays.asList("Blue", "Black", "White")); // Arrays.asList() HashSet colors.. 2023. 11. 7.
[자료구조] Vector - ArrayList와 비슷한 성질(크기가 가변적으로 변함)을 가지고 있다. - ArrayList와 다르게 동기화를 제공한다. - 동기화를 제공하기 때문에 멀티 스레드 환경에서 안전(Thread Safe) 하며 이로 인해 낮은 성능을 보인다. 생성 import java.util.Vetor; Vector vector1 = new Vector(); // 타입 지정 Vector vector2 = new Vector(); // 타입 생략 가능 Vector vector3 = new Vector>(10); // 초기 용량(Capacity) 설정 Vector vector4 = new Vector (10, 10); // 초기 용량, 증가량 설정 Vector vector5 = new Vector (vector1); //.. 2023. 11. 6.
[자료구조] Stack - 먼저 들어간 데이터가 나중에 나오는 LIFO(Last In First Out) 구조 - 스택의 크기만큼 데이터가 꽉 차서 데이터를 넣지 못할 때 → Overflow - 스택이 비어있는데, 데이터를 꺼내려고 하는 경우 → Underflow 생성 import java.util.Stack; //import Stack stack = new Stack(); // int형 스택 선언 Stack stack = new Stack(); // char형 스택 선언 추가 및 변경 Stack stack = new Stack(); // int형 스택 선언 stack.push(1); // stack에 값 1 추가 stack.push(2); // stack에 값 2 추가 stack.push(3); // stack에 값 3 추가.. 2023. 11. 6.
[자료구조] ArrayList - 가장 대표적인 List형태의 자료구조이다. - 이어 쓰고 읽기에 가장 적합한 구조이다.(연속된 메모리 공간을 사용) - ArrayList의 크기는 자동으로 조정된다. - 동기화를 제공하지 않는다. ArrayList 생성 import java.util.ArrayList; ArrayList integers1 = new ArrayList(); // 타입 지정 ArrayList integers2 = new ArrayList(); // 타입 생략 가능 ArrayList integers3 = new ArrayList(10); // 초기 용량(Capacity) 설정 ArrayList integers4 = new ArrayList(integers1); // 다른 Collection값으로 초기화 ArrayList i.. 2023. 11. 3.