SlideShare a Scribd company logo
1 of 18
Download to read offline
DataAnalysis
(Lecture 5 – LinkedList)
1
Jaewook Byun
Ph.D. Assistant Professor, Department of Software, Sejong University
Associate Director, Auto-ID Labs, Korea
jwbyun@sejong.ac.kr , bjw0829@gmail.com
https://sites.google.com/view/jack-dfpl/home
https://www.youtube.com/channel/UC988e-Y8nto0LXVae0aqaOQ
목차
• LinkedList 소개
• LinkedList CRUD 연산
2
I. java.util.LinkedList 소개
1) java.util.LinkedList의 계층구조
3
• 본 과정에서는 List + Queue 로서의 LinkedList를 살펴볼 예정
Collection
List
ArrayList
LinkedList
Queue
I. java.util.LinkedList 소개
2) List 복습
4
• 순서화 된 중복을 허용하는 Collection
• Collection 내의 Instance가 위치할 위치인 Index를 통해 조작
• 구현에 따라 제공하는 연산의 효율이 다를 수 있음
• 구현물: ArrayList, LinkedList, Stack 등
Collection
List
ArrayList
중복허용 순서 유지 Thread-Safe
O O ?
중복허용 순서 유지 Thread-Safe
O O X
LinkedList
중복허용 순서 유지 Thread-Safe
O O X
LinkedList
중복허용 순서 유지 Thread-Safe
O O O
I. java.util.LinkedList 소개
2) List 복습
5
• 순서화 된 중복을 허용하는 Collection
• Collection 내의 Instance가 위치할 위치인 Index를 통해 조작
Return Type Method Description
boolean isEmpty() Collection이 비어 있는지 확인
int size() Collection의 크기를 반환
boolean add​(E e) Collection에 새로운 instance를 삽입
void add(int index, E element) List의 특정 위치에 instance를 삽입
boolean contains​(Object o) Collection에 o라는 instance가 있는지 확인
E get(int index) List의 특정 위치에 있는 instance를 추출
int indexOf(Object o) List에서 instance o의 위치를 찾기 (앞에서부터)
int lastIndexOf(Object o) List에서 instance o의 위치를 찾기 (뒤에서부터)
E set(int index, E element) List의 특정 위치의 instance 값을 element로 업데이트
boolean remove​(Object o) Collection에 o라는 instance가 있다면 삭제
E remove(int index) List의 특정 위치에 있는 instance를 삭제
Iterator<E> iterator() Collection을 순회할 수 있는 iterator를 반환
ListIterator<E> listIterator(int index) List를 순회할 수 있는 listIterator를 반환
void clear() Collection을 비움
Object[] toArray​() Collection을 배열에 담음
void sort(Comparator<? super E> comparator) List를 특정 비교방법에 의해 정렬함
List<E> subList(int from, int to) List의 부분을 가져온다
Stream<E> stream() Collection에 대한 Stream을 반환
META
C
R
D
T
U
I. java.util.LinkedList 소개
3) Queue 소개
6
• 삽입과 추출이 한 방향에서만 일어나는 컬렉션
• 먼저 삽입된 instance가 먼저 추출됨
• First In First Out (FIFO)
• 응용: 버퍼, 스케쥴러
Last
First
Offer
Poll
I. java.util.LinkedList 소개
3) Queue 소개
7
• 삽입과 추출이 한 방향에서만 일어나는 컬렉션
• 먼저 삽입된 instance가 먼저 추출됨
• First In First Out (FIFO)
• 응용: 버퍼, 스케쥴러
Return Type Method Description
boolean isEmpty() Collection이 비어 있는지 확인
int size() Collection의 크기를 반환
boolean add​(E e) Collection에 새로운 instance를 삽입 (Capacity 초과시 Exception 발생)
boolean offer(E e) Queue에 새로운 instance를 마지막에 삽입 (Capacity 초과시 false 반환)
boolean contains​(Object o) Collection에 o라는 instance가 있는지 확인
E element() Queue의 처음 instance를 반환 (비어있을 때 Exception 발생)
E peek() Queue의 처음 instance를 반환 (비어있을 때 null 반환)
boolean remove​(Object o) Collection에 o라는 instance가 있다면 삭제
E remove() Queue의 처음 instance를 지우고 반환 (비어있을 때 Exception 발생)
E poll() Queue의 처음 instance를 지우고 반환 (비어있을 때 null 반환)
Iterator<E> iterator() Collection을 순회할 수 있는 iterator를 반환
void clear() Collection을 비움
Object[] toArray​() Collection을 배열에 담음
Stream<E> stream() Collection에 대한 Stream을 반환
META
C
R
D
T
I. java.util.LinkedList 소개
4) LinkedList 소개
8
• Array를 기반으로 한 것이 아닌, 객체 Node 간을 연결을 이용하여 설계한 컬렉션
• java.util.LinkedList는 객체가 다음의 객체와 이전의 객체에 대한 참조를 갖고 있는
Doubly Linked List 임
유튜브 - https://youtu.be/rwt1xIB7UBw
prev prev
data
Node:
3
Doubly
Linked List: start last
2
1
null null
size = 3
index = 0
get(0) → 1
Poll
Offer
II. java.util.LinkedList CRUD
1) LinkedList 복습
9
Return Type Method Description
boolean isEmpty() Collection이 비어 있는지 확인
int size() Collection의 크기를 반환
boolean add​(E e) Collection에 새로운 instance를 삽입 (Capacity 초과시 Exception 발생)
void add(int index, E element) List의 특정 위치에 instance를 삽입
boolean offer(E e) Queue에 새로운 instance를 마지막에 삽입 (Capacity 초과시 false 반환)
boolean contains​(Object o) Collection에 o라는 instance가 있는지 확인
E get(int index) List의 특정 위치에 있는 instance를 추출
int indexOf(Object o) List에서 instance o의 위치를 찾기 (앞에서부터)
int lastIndexOf(Object o) List에서 instance o의 위치를 찾기 (뒤에서부터)
E element() Queue의 처음 instance를 반환 (비어있을 때 Exception 발생)
E peek() Queue의 처음 instance를 반환 (비어있을 때 null 반환)
E set(int index, E element) List의 특정 위치의 instance 값을 element로 업데이트
boolean remove​(Object o) Collection에 o라는 instance가 있다면 삭제
E remove(int index) List의 특정 위치에 있는 instance를 삭제
E remove() Queue의 처음 instance를 지우고 반환 (비어있을 때 Exception 발생)
E poll() Queue의 처음 instance를 지우고 반환 (비어있을 때 null 반환)
Iterator<E> iterator() Collection을 순회할 수 있는 iterator를 반환
ListIterator<E> listIterator(int index) List를 순회할 수 있는 listIterator를 반환
void clear() Collection을 비움
Object[] toArray​() Collection을 배열에 담음
void sort(Comparator<? super E> comparator) List를 특정 비교방법에 의해 정렬함
List<E> subList(int from, int to) List의 부분을 가져온다
META
C
R
D
T
U
II. java.util.LinkedList CRUD
2) LinkedList CRUD
10
• Array를 기반으로 한 것이 아닌, 객체 Node 간을 연결을 이용하여 설계한 Doubly
Linked List 구현
유튜브 - https://youtu.be/f_qQbQHfAO0
Return Type Method Description
생성자 LinkedList() 빈 LinkedList를 생성
생성자 LinkedList(Collection c) LinkedList를 Collection c의 요소를 가져와 생성
JVM Heap
LinkedList<Integer> linkedList = new LinkedList<Integer>();
LinkedList
[ ]
1. 빈 리스트 생성
2. 주소할당
Collection<Integer> collection = arrayList; // [0,1,2,3,4] ArrayList
LinkedList<Integer> linkedList = new LinkedList<Integer>(collection);
LinkedList
[0,1,2,3,4]
1. 컬렉션으로 리스트 생성
2. 주소할당
II. java.util.LinkedList CRUD
2) LinkedList CRUD
11
Return Type Method Description
boolean isEmpty() Collection이 비어 있는지 확인
int size() Collection의 크기를 반환
boolean add​(E e) Collection에 새로운 instance를 삽입 (Capacity 초과시 Exception 발생)
void add(int index, E element) List의 특정 위치에 instance를 삽입
3
start last
2
1
null null
isEmpty() → false
size() → 3
add(4)
3
start last
2
1
null 4
생성 및 참조 조정
유튜브 - https://youtu.be/zbs4RhZ13sw
II. java.util.LinkedList CRUD
2) LinkedList CRUD
12
Return Type Method Description
boolean contains​(Object o) Collection에 o라는 instance가 있는지 확인
E get(int index) List의 특정 위치에 있는 instance를 추출
int indexOf(Object o) List에서 instance o의 위치를 찾기 (앞에서부터)
int lastIndexOf(Object o) List에서 instance o의 위치를 찾기 (뒤에서부터)
3
first last
2
1
null null
contains(1)
true
2
get(3)
3
indexOf(2) lastIndexOf(2)
1 2
유튜브 - https://youtu.be/0mMDuAeqZOo
II. java.util.LinkedList CRUD
2) LinkedList CRUD
13
Return Type Method Description
E set(int index, E element) 컬렉션의 특정 위치의 instance 값을 element로 업데이트
boolean remove​(Object o) 컬렉션에 o라는 instance가 있다면 삭제
E remove(int index) 컬렉션의 특정 위치에 있는 instance를 삭제
3
start last
2
1
3
null null
2
set(0,3)
remove(3)
3
start last
2
3
null null
2 null
제거 및 참조 조정
유튜브 - https://youtu.be/qqdkEkk20gA
II. java.util.LinkedList CRUD
2) LinkedList CRUD
14
Return Type Method Description
Iterator<E> iterator() Collection을 순회할 수 있는 iterator를 반환
ListIterator<E> listIterator(int index) List를 순회할 수 있는 listIterator를 반환
3
start last
2
1
null null
index: -1 index: 0 index: 1 index: 2
(size-1)
index: size
List list에 대한 Cursor와 메소드 동작
초기 cursor 값
iterator() → -1
listIterator(int index) → index -1
즉, iterator() == listIterator(0)
previousIndex() cursor 반환
previous() list.get(cursor) 반환 후 cursor-- 수행
hasPrevious() list.get(cursor) == null 반환
nextIndex() cursor + 1 반환
next() list.get(cursor+1) 반환 후 cursor++ 수행
hasNext() list.get(cursor+1) == null 반환
ListIterator<Integer> ai = list.listIterator(0);
while (ai.hasNext()) {
Integer value = ai.next(); // Do Something
}
ListIterator<Integer> di =
list.listIterator(list.size());
while (di.hasPrevious()) {
Integer value = di.previous();// Do Something
}
순회 패턴1: 앞에서 부터
순회 패턴2: 뒤에서 부터
유튜브 - https://youtu.be/AFuXpnPsHfs
II. java.util.LinkedList CRUD
2) LinkedList CRUD
15
유튜브 - https://youtu.be/iZHVYhwmyR8
Return Type Method Description
void clear() Collection을 비움
Object[] toArray​() Collection을 배열에 담음
void sort(Comparator<? super E> comparator) List를 특정 비교방법에 의해 정렬함
List<E> subList(int from, int to) List의 부분을 가져온다
first last
null
clear()
인덱스
값
Object[]
toArray()
sort(c)
subList(2,4)
first last
II. java.util.LinkedList CRUD
2) LinkedList CRUD
16
유튜브 - https://youtu.be/8Vp477YQNE8
Return Type Method Description
boolean add​(E e) Collection에 새로운 instance를 삽입 (Capacity 초과시 Exception 발생)
boolean offer(E e) Queue에 새로운 instance를 마지막에 삽입 (Capacity 초과시 false 반환)
first last
2
1 3
4
last
first
2
1 3
add(4)
offer(4)
II. java.util.LinkedList CRUD
2) LinkedList CRUD
17
유튜브 - https://youtu.be/U2ndWwtSxWQ
Return Type Method Description
E element() 컬렉션의 처음 instance를 반환 (비어있을 때 Exception 발생)
E peek() 컬렉션의 처음 instance를 반환 (비어있을 때 null 반환)
first last
2
1 3
element()
peek()
1 반환
first last
null
element()
peek() null 반환
II. java.util.LinkedList CRUD
2) LinkedList CRUD
18
유튜브 - https://youtu.be/ZD4hukMaHrw
Return Type Method Description
E remove() 컬렉션의 처음 instance를 지우고 반환 (비어있을 때 Exception 발생)
E poll() 컬렉션의 처음 instance를 지우고 반환 (비어있을 때 null 반환)
start last
2
1 3
start
2
1 3
remove()
poll()
last

More Related Content

What's hot

SpringCamp 2013 : About Jdk8
SpringCamp 2013 : About Jdk8SpringCamp 2013 : About Jdk8
SpringCamp 2013 : About Jdk8Sangmin Lee
 
[2012 자바카페 OPEN 세미나] Introduction to google guava
[2012 자바카페 OPEN 세미나] Introduction to google guava[2012 자바카페 OPEN 세미나] Introduction to google guava
[2012 자바카페 OPEN 세미나] Introduction to google guava흥래 김
 
빠르게 활용하는 파이썬3 스터디(ch1~4)
빠르게 활용하는 파이썬3 스터디(ch1~4)빠르게 활용하는 파이썬3 스터디(ch1~4)
빠르게 활용하는 파이썬3 스터디(ch1~4)SeongHyun Ahn
 
Python 활용: 이미지 처리와 데이터 분석
Python 활용: 이미지 처리와 데이터 분석Python 활용: 이미지 처리와 데이터 분석
Python 활용: 이미지 처리와 데이터 분석용 최
 
20111025 Excel의 VBA, 매크로. 그리고 파이썬으로 함께하는 반복작업
20111025 Excel의 VBA, 매크로. 그리고 파이썬으로 함께하는 반복작업20111025 Excel의 VBA, 매크로. 그리고 파이썬으로 함께하는 반복작업
20111025 Excel의 VBA, 매크로. 그리고 파이썬으로 함께하는 반복작업Jiho Lee
 
Python programming for Bioinformatics
Python programming for BioinformaticsPython programming for Bioinformatics
Python programming for BioinformaticsHyungyong Kim
 
알고리즘과 자료구조
알고리즘과 자료구조알고리즘과 자료구조
알고리즘과 자료구조영기 김
 
Python Programming: Function
Python Programming: FunctionPython Programming: Function
Python Programming: FunctionChan Shik Lim
 
10장 문자열클래스와파일클래스
10장 문자열클래스와파일클래스10장 문자열클래스와파일클래스
10장 문자열클래스와파일클래스웅식 전
 
씹고 뜯고 맛보고 즐기는 스트림 API
씹고 뜯고 맛보고 즐기는 스트림 API씹고 뜯고 맛보고 즐기는 스트림 API
씹고 뜯고 맛보고 즐기는 스트림 APIArawn Park
 
JVM 메모리 해부학
JVM 메모리 해부학JVM 메모리 해부학
JVM 메모리 해부학Greg Lee
 
10장 문자열 클래스와 파일 클래스
10장 문자열 클래스와 파일 클래스10장 문자열 클래스와 파일 클래스
10장 문자열 클래스와 파일 클래스유석 남
 
1.자료구조와 알고리즘(강의자료)
1.자료구조와 알고리즘(강의자료)1.자료구조와 알고리즘(강의자료)
1.자료구조와 알고리즘(강의자료)fmbvbfhs
 
[Swift] Data Structure - Heap
[Swift] Data Structure - Heap[Swift] Data Structure - Heap
[Swift] Data Structure - HeapBill Kim
 
자바8 람다 나머지 공개
자바8 람다 나머지 공개자바8 람다 나머지 공개
자바8 람다 나머지 공개Sungchul Park
 

What's hot (20)

Fp basic-kotlin
Fp basic-kotlinFp basic-kotlin
Fp basic-kotlin
 
SpringCamp 2013 : About Jdk8
SpringCamp 2013 : About Jdk8SpringCamp 2013 : About Jdk8
SpringCamp 2013 : About Jdk8
 
[2012 자바카페 OPEN 세미나] Introduction to google guava
[2012 자바카페 OPEN 세미나] Introduction to google guava[2012 자바카페 OPEN 세미나] Introduction to google guava
[2012 자바카페 OPEN 세미나] Introduction to google guava
 
Java collection
Java collectionJava collection
Java collection
 
빠르게 활용하는 파이썬3 스터디(ch1~4)
빠르게 활용하는 파이썬3 스터디(ch1~4)빠르게 활용하는 파이썬3 스터디(ch1~4)
빠르게 활용하는 파이썬3 스터디(ch1~4)
 
Scala
ScalaScala
Scala
 
Python 활용: 이미지 처리와 데이터 분석
Python 활용: 이미지 처리와 데이터 분석Python 활용: 이미지 처리와 데이터 분석
Python 활용: 이미지 처리와 데이터 분석
 
20111025 Excel의 VBA, 매크로. 그리고 파이썬으로 함께하는 반복작업
20111025 Excel의 VBA, 매크로. 그리고 파이썬으로 함께하는 반복작업20111025 Excel의 VBA, 매크로. 그리고 파이썬으로 함께하는 반복작업
20111025 Excel의 VBA, 매크로. 그리고 파이썬으로 함께하는 반복작업
 
Python programming for Bioinformatics
Python programming for BioinformaticsPython programming for Bioinformatics
Python programming for Bioinformatics
 
알고리즘과 자료구조
알고리즘과 자료구조알고리즘과 자료구조
알고리즘과 자료구조
 
Python Programming: Function
Python Programming: FunctionPython Programming: Function
Python Programming: Function
 
Just java
Just javaJust java
Just java
 
10장 문자열클래스와파일클래스
10장 문자열클래스와파일클래스10장 문자열클래스와파일클래스
10장 문자열클래스와파일클래스
 
씹고 뜯고 맛보고 즐기는 스트림 API
씹고 뜯고 맛보고 즐기는 스트림 API씹고 뜯고 맛보고 즐기는 스트림 API
씹고 뜯고 맛보고 즐기는 스트림 API
 
JVM 메모리 해부학
JVM 메모리 해부학JVM 메모리 해부학
JVM 메모리 해부학
 
10장 문자열 클래스와 파일 클래스
10장 문자열 클래스와 파일 클래스10장 문자열 클래스와 파일 클래스
10장 문자열 클래스와 파일 클래스
 
1.자료구조와 알고리즘(강의자료)
1.자료구조와 알고리즘(강의자료)1.자료구조와 알고리즘(강의자료)
1.자료구조와 알고리즘(강의자료)
 
[Swift] Data Structure - Heap
[Swift] Data Structure - Heap[Swift] Data Structure - Heap
[Swift] Data Structure - Heap
 
자바8 람다 나머지 공개
자바8 람다 나머지 공개자바8 람다 나머지 공개
자바8 람다 나머지 공개
 
Java(4/4)
Java(4/4)Java(4/4)
Java(4/4)
 

Similar to 데이터 분석 5 - Java Collection Framework - LinkedList 파헤치기

[Swift] Iterator
[Swift] Iterator[Swift] Iterator
[Swift] IteratorBill Kim
 
[Swift] Data Structure - Queue
[Swift] Data Structure - Queue[Swift] Data Structure - Queue
[Swift] Data Structure - QueueBill Kim
 
파이썬 Collections 모듈 이해하기
파이썬 Collections 모듈 이해하기파이썬 Collections 모듈 이해하기
파이썬 Collections 모듈 이해하기Yong Joon Moon
 
Swift3 generic
Swift3 genericSwift3 generic
Swift3 genericEunjoo Im
 
Python + Excel
Python + Excel Python + Excel
Python + Excel POSTECH
 
[Algorithm] Counting Sort
[Algorithm] Counting Sort[Algorithm] Counting Sort
[Algorithm] Counting SortBill Kim
 
[Swift] Data Structure - Array
[Swift] Data Structure - Array[Swift] Data Structure - Array
[Swift] Data Structure - ArrayBill Kim
 
[Swift] Data Structure - Stack
[Swift] Data Structure - Stack[Swift] Data Structure - Stack
[Swift] Data Structure - StackBill Kim
 
실용주의 디자인패턴 2 인터페이스로 프로그래밍하기
실용주의 디자인패턴   2 인터페이스로 프로그래밍하기실용주의 디자인패턴   2 인터페이스로 프로그래밍하기
실용주의 디자인패턴 2 인터페이스로 프로그래밍하기Cosmos Shin
 
파이썬정리 20160130
파이썬정리 20160130파이썬정리 20160130
파이썬정리 20160130Yong Joon Moon
 
[Commit Again] 1주차 STL study
[Commit Again] 1주차 STL study[Commit Again] 1주차 STL study
[Commit Again] 1주차 STL study경 송
 
개경프 1주차 Stl study
개경프 1주차 Stl study개경프 1주차 Stl study
개경프 1주차 Stl study경 송
 
Data structure review (summer study)
Data structure review (summer study)Data structure review (summer study)
Data structure review (summer study)Melon Lemon
 
Swift3 subscript inheritance initialization
Swift3 subscript inheritance initializationSwift3 subscript inheritance initialization
Swift3 subscript inheritance initializationEunjoo Im
 
[Swift] Data Structure - Linked List
[Swift] Data Structure - Linked List[Swift] Data Structure - Linked List
[Swift] Data Structure - Linked ListBill Kim
 

Similar to 데이터 분석 5 - Java Collection Framework - LinkedList 파헤치기 (20)

Java_08 collection
Java_08 collectionJava_08 collection
Java_08 collection
 
[Swift] Iterator
[Swift] Iterator[Swift] Iterator
[Swift] Iterator
 
[Swift] Data Structure - Queue
[Swift] Data Structure - Queue[Swift] Data Structure - Queue
[Swift] Data Structure - Queue
 
파이썬 Collections 모듈 이해하기
파이썬 Collections 모듈 이해하기파이썬 Collections 모듈 이해하기
파이썬 Collections 모듈 이해하기
 
Swift3 generic
Swift3 genericSwift3 generic
Swift3 generic
 
Python + Excel
Python + Excel Python + Excel
Python + Excel
 
[Algorithm] Counting Sort
[Algorithm] Counting Sort[Algorithm] Counting Sort
[Algorithm] Counting Sort
 
[Swift] Data Structure - Array
[Swift] Data Structure - Array[Swift] Data Structure - Array
[Swift] Data Structure - Array
 
[Swift] Data Structure - Stack
[Swift] Data Structure - Stack[Swift] Data Structure - Stack
[Swift] Data Structure - Stack
 
실용주의 디자인패턴 2 인터페이스로 프로그래밍하기
실용주의 디자인패턴   2 인터페이스로 프로그래밍하기실용주의 디자인패턴   2 인터페이스로 프로그래밍하기
실용주의 디자인패턴 2 인터페이스로 프로그래밍하기
 
4. stack
4. stack4. stack
4. stack
 
강의자료3
강의자료3강의자료3
강의자료3
 
파이썬정리 20160130
파이썬정리 20160130파이썬정리 20160130
파이썬정리 20160130
 
5. queue
5. queue5. queue
5. queue
 
[Commit Again] 1주차 STL study
[Commit Again] 1주차 STL study[Commit Again] 1주차 STL study
[Commit Again] 1주차 STL study
 
개경프 1주차 Stl study
개경프 1주차 Stl study개경프 1주차 Stl study
개경프 1주차 Stl study
 
Data structure review (summer study)
Data structure review (summer study)Data structure review (summer study)
Data structure review (summer study)
 
강의자료5
강의자료5강의자료5
강의자료5
 
Swift3 subscript inheritance initialization
Swift3 subscript inheritance initializationSwift3 subscript inheritance initialization
Swift3 subscript inheritance initialization
 
[Swift] Data Structure - Linked List
[Swift] Data Structure - Linked List[Swift] Data Structure - Linked List
[Swift] Data Structure - Linked List
 

데이터 분석 5 - Java Collection Framework - LinkedList 파헤치기

  • 1. DataAnalysis (Lecture 5 – LinkedList) 1 Jaewook Byun Ph.D. Assistant Professor, Department of Software, Sejong University Associate Director, Auto-ID Labs, Korea jwbyun@sejong.ac.kr , bjw0829@gmail.com https://sites.google.com/view/jack-dfpl/home https://www.youtube.com/channel/UC988e-Y8nto0LXVae0aqaOQ
  • 2. 목차 • LinkedList 소개 • LinkedList CRUD 연산 2
  • 3. I. java.util.LinkedList 소개 1) java.util.LinkedList의 계층구조 3 • 본 과정에서는 List + Queue 로서의 LinkedList를 살펴볼 예정 Collection List ArrayList LinkedList Queue
  • 4. I. java.util.LinkedList 소개 2) List 복습 4 • 순서화 된 중복을 허용하는 Collection • Collection 내의 Instance가 위치할 위치인 Index를 통해 조작 • 구현에 따라 제공하는 연산의 효율이 다를 수 있음 • 구현물: ArrayList, LinkedList, Stack 등 Collection List ArrayList 중복허용 순서 유지 Thread-Safe O O ? 중복허용 순서 유지 Thread-Safe O O X LinkedList 중복허용 순서 유지 Thread-Safe O O X LinkedList 중복허용 순서 유지 Thread-Safe O O O
  • 5. I. java.util.LinkedList 소개 2) List 복습 5 • 순서화 된 중복을 허용하는 Collection • Collection 내의 Instance가 위치할 위치인 Index를 통해 조작 Return Type Method Description boolean isEmpty() Collection이 비어 있는지 확인 int size() Collection의 크기를 반환 boolean add​(E e) Collection에 새로운 instance를 삽입 void add(int index, E element) List의 특정 위치에 instance를 삽입 boolean contains​(Object o) Collection에 o라는 instance가 있는지 확인 E get(int index) List의 특정 위치에 있는 instance를 추출 int indexOf(Object o) List에서 instance o의 위치를 찾기 (앞에서부터) int lastIndexOf(Object o) List에서 instance o의 위치를 찾기 (뒤에서부터) E set(int index, E element) List의 특정 위치의 instance 값을 element로 업데이트 boolean remove​(Object o) Collection에 o라는 instance가 있다면 삭제 E remove(int index) List의 특정 위치에 있는 instance를 삭제 Iterator<E> iterator() Collection을 순회할 수 있는 iterator를 반환 ListIterator<E> listIterator(int index) List를 순회할 수 있는 listIterator를 반환 void clear() Collection을 비움 Object[] toArray​() Collection을 배열에 담음 void sort(Comparator<? super E> comparator) List를 특정 비교방법에 의해 정렬함 List<E> subList(int from, int to) List의 부분을 가져온다 Stream<E> stream() Collection에 대한 Stream을 반환 META C R D T U
  • 6. I. java.util.LinkedList 소개 3) Queue 소개 6 • 삽입과 추출이 한 방향에서만 일어나는 컬렉션 • 먼저 삽입된 instance가 먼저 추출됨 • First In First Out (FIFO) • 응용: 버퍼, 스케쥴러 Last First Offer Poll
  • 7. I. java.util.LinkedList 소개 3) Queue 소개 7 • 삽입과 추출이 한 방향에서만 일어나는 컬렉션 • 먼저 삽입된 instance가 먼저 추출됨 • First In First Out (FIFO) • 응용: 버퍼, 스케쥴러 Return Type Method Description boolean isEmpty() Collection이 비어 있는지 확인 int size() Collection의 크기를 반환 boolean add​(E e) Collection에 새로운 instance를 삽입 (Capacity 초과시 Exception 발생) boolean offer(E e) Queue에 새로운 instance를 마지막에 삽입 (Capacity 초과시 false 반환) boolean contains​(Object o) Collection에 o라는 instance가 있는지 확인 E element() Queue의 처음 instance를 반환 (비어있을 때 Exception 발생) E peek() Queue의 처음 instance를 반환 (비어있을 때 null 반환) boolean remove​(Object o) Collection에 o라는 instance가 있다면 삭제 E remove() Queue의 처음 instance를 지우고 반환 (비어있을 때 Exception 발생) E poll() Queue의 처음 instance를 지우고 반환 (비어있을 때 null 반환) Iterator<E> iterator() Collection을 순회할 수 있는 iterator를 반환 void clear() Collection을 비움 Object[] toArray​() Collection을 배열에 담음 Stream<E> stream() Collection에 대한 Stream을 반환 META C R D T
  • 8. I. java.util.LinkedList 소개 4) LinkedList 소개 8 • Array를 기반으로 한 것이 아닌, 객체 Node 간을 연결을 이용하여 설계한 컬렉션 • java.util.LinkedList는 객체가 다음의 객체와 이전의 객체에 대한 참조를 갖고 있는 Doubly Linked List 임 유튜브 - https://youtu.be/rwt1xIB7UBw prev prev data Node: 3 Doubly Linked List: start last 2 1 null null size = 3 index = 0 get(0) → 1 Poll Offer
  • 9. II. java.util.LinkedList CRUD 1) LinkedList 복습 9 Return Type Method Description boolean isEmpty() Collection이 비어 있는지 확인 int size() Collection의 크기를 반환 boolean add​(E e) Collection에 새로운 instance를 삽입 (Capacity 초과시 Exception 발생) void add(int index, E element) List의 특정 위치에 instance를 삽입 boolean offer(E e) Queue에 새로운 instance를 마지막에 삽입 (Capacity 초과시 false 반환) boolean contains​(Object o) Collection에 o라는 instance가 있는지 확인 E get(int index) List의 특정 위치에 있는 instance를 추출 int indexOf(Object o) List에서 instance o의 위치를 찾기 (앞에서부터) int lastIndexOf(Object o) List에서 instance o의 위치를 찾기 (뒤에서부터) E element() Queue의 처음 instance를 반환 (비어있을 때 Exception 발생) E peek() Queue의 처음 instance를 반환 (비어있을 때 null 반환) E set(int index, E element) List의 특정 위치의 instance 값을 element로 업데이트 boolean remove​(Object o) Collection에 o라는 instance가 있다면 삭제 E remove(int index) List의 특정 위치에 있는 instance를 삭제 E remove() Queue의 처음 instance를 지우고 반환 (비어있을 때 Exception 발생) E poll() Queue의 처음 instance를 지우고 반환 (비어있을 때 null 반환) Iterator<E> iterator() Collection을 순회할 수 있는 iterator를 반환 ListIterator<E> listIterator(int index) List를 순회할 수 있는 listIterator를 반환 void clear() Collection을 비움 Object[] toArray​() Collection을 배열에 담음 void sort(Comparator<? super E> comparator) List를 특정 비교방법에 의해 정렬함 List<E> subList(int from, int to) List의 부분을 가져온다 META C R D T U
  • 10. II. java.util.LinkedList CRUD 2) LinkedList CRUD 10 • Array를 기반으로 한 것이 아닌, 객체 Node 간을 연결을 이용하여 설계한 Doubly Linked List 구현 유튜브 - https://youtu.be/f_qQbQHfAO0 Return Type Method Description 생성자 LinkedList() 빈 LinkedList를 생성 생성자 LinkedList(Collection c) LinkedList를 Collection c의 요소를 가져와 생성 JVM Heap LinkedList<Integer> linkedList = new LinkedList<Integer>(); LinkedList [ ] 1. 빈 리스트 생성 2. 주소할당 Collection<Integer> collection = arrayList; // [0,1,2,3,4] ArrayList LinkedList<Integer> linkedList = new LinkedList<Integer>(collection); LinkedList [0,1,2,3,4] 1. 컬렉션으로 리스트 생성 2. 주소할당
  • 11. II. java.util.LinkedList CRUD 2) LinkedList CRUD 11 Return Type Method Description boolean isEmpty() Collection이 비어 있는지 확인 int size() Collection의 크기를 반환 boolean add​(E e) Collection에 새로운 instance를 삽입 (Capacity 초과시 Exception 발생) void add(int index, E element) List의 특정 위치에 instance를 삽입 3 start last 2 1 null null isEmpty() → false size() → 3 add(4) 3 start last 2 1 null 4 생성 및 참조 조정 유튜브 - https://youtu.be/zbs4RhZ13sw
  • 12. II. java.util.LinkedList CRUD 2) LinkedList CRUD 12 Return Type Method Description boolean contains​(Object o) Collection에 o라는 instance가 있는지 확인 E get(int index) List의 특정 위치에 있는 instance를 추출 int indexOf(Object o) List에서 instance o의 위치를 찾기 (앞에서부터) int lastIndexOf(Object o) List에서 instance o의 위치를 찾기 (뒤에서부터) 3 first last 2 1 null null contains(1) true 2 get(3) 3 indexOf(2) lastIndexOf(2) 1 2 유튜브 - https://youtu.be/0mMDuAeqZOo
  • 13. II. java.util.LinkedList CRUD 2) LinkedList CRUD 13 Return Type Method Description E set(int index, E element) 컬렉션의 특정 위치의 instance 값을 element로 업데이트 boolean remove​(Object o) 컬렉션에 o라는 instance가 있다면 삭제 E remove(int index) 컬렉션의 특정 위치에 있는 instance를 삭제 3 start last 2 1 3 null null 2 set(0,3) remove(3) 3 start last 2 3 null null 2 null 제거 및 참조 조정 유튜브 - https://youtu.be/qqdkEkk20gA
  • 14. II. java.util.LinkedList CRUD 2) LinkedList CRUD 14 Return Type Method Description Iterator<E> iterator() Collection을 순회할 수 있는 iterator를 반환 ListIterator<E> listIterator(int index) List를 순회할 수 있는 listIterator를 반환 3 start last 2 1 null null index: -1 index: 0 index: 1 index: 2 (size-1) index: size List list에 대한 Cursor와 메소드 동작 초기 cursor 값 iterator() → -1 listIterator(int index) → index -1 즉, iterator() == listIterator(0) previousIndex() cursor 반환 previous() list.get(cursor) 반환 후 cursor-- 수행 hasPrevious() list.get(cursor) == null 반환 nextIndex() cursor + 1 반환 next() list.get(cursor+1) 반환 후 cursor++ 수행 hasNext() list.get(cursor+1) == null 반환 ListIterator<Integer> ai = list.listIterator(0); while (ai.hasNext()) { Integer value = ai.next(); // Do Something } ListIterator<Integer> di = list.listIterator(list.size()); while (di.hasPrevious()) { Integer value = di.previous();// Do Something } 순회 패턴1: 앞에서 부터 순회 패턴2: 뒤에서 부터 유튜브 - https://youtu.be/AFuXpnPsHfs
  • 15. II. java.util.LinkedList CRUD 2) LinkedList CRUD 15 유튜브 - https://youtu.be/iZHVYhwmyR8 Return Type Method Description void clear() Collection을 비움 Object[] toArray​() Collection을 배열에 담음 void sort(Comparator<? super E> comparator) List를 특정 비교방법에 의해 정렬함 List<E> subList(int from, int to) List의 부분을 가져온다 first last null clear() 인덱스 값 Object[] toArray() sort(c) subList(2,4) first last
  • 16. II. java.util.LinkedList CRUD 2) LinkedList CRUD 16 유튜브 - https://youtu.be/8Vp477YQNE8 Return Type Method Description boolean add​(E e) Collection에 새로운 instance를 삽입 (Capacity 초과시 Exception 발생) boolean offer(E e) Queue에 새로운 instance를 마지막에 삽입 (Capacity 초과시 false 반환) first last 2 1 3 4 last first 2 1 3 add(4) offer(4)
  • 17. II. java.util.LinkedList CRUD 2) LinkedList CRUD 17 유튜브 - https://youtu.be/U2ndWwtSxWQ Return Type Method Description E element() 컬렉션의 처음 instance를 반환 (비어있을 때 Exception 발생) E peek() 컬렉션의 처음 instance를 반환 (비어있을 때 null 반환) first last 2 1 3 element() peek() 1 반환 first last null element() peek() null 반환
  • 18. II. java.util.LinkedList CRUD 2) LinkedList CRUD 18 유튜브 - https://youtu.be/ZD4hukMaHrw Return Type Method Description E remove() 컬렉션의 처음 instance를 지우고 반환 (비어있을 때 Exception 발생) E poll() 컬렉션의 처음 instance를 지우고 반환 (비어있을 때 null 반환) start last 2 1 3 start 2 1 3 remove() poll() last