Code&Data Insights

[ Java Programming ] LinkedList / LinkedList vs ArrayList 본문

Computer Science/Java Programming

[ Java Programming ] LinkedList / LinkedList vs ArrayList

paka_corn 2022. 6. 2. 05:29

[ Linked List ] 

- 자바의 Collection Framework에 포함.

 

- This class is an implementation of the LinkedList data structure which is a linear data structure where the elements are not stored in contiguous locations and every element is a separate object with a data part and address part. 

 

- 각 element들(node)은 pointer와 address로 연결되어져 있다. 

 

- 각 element들의 위치 파악이 어려워 불연속적이다. ( 접근성 ↓)

 

 

 

 

 

[ Linked List vs ArrayList ] 

 

Linked List - much faster for add/delete value  *추가/삭제에 용이* 

 

ArrayList - much faster for retrieving the specific value, random access  *특정  element를 검색하는데 용이 *

 

 

=> Both look similar, but behind the scene, they act differently! 

프로그램 성향에 따라 어떤 리스트 collection frame work를 사용해야 할 지 선택할 수 있다. 

 

 

==> 이미 만들어진 arraylist에서 검색을 주로 하는 프로그램이면, arraylist가 훨씬 빠르다. ( Linked List는 검색을 하기위해 모든 연결된 node를 거쳐가야 하기 때문에 상대적으로 매우 느리다. ) 

- It also has a few disadvantages like the nodes cannot be accessed directly instead we need to start from the head and follow through the link to reach a node we wish to access.

 

==> List내에 추가,삭제(Add and delete) 가 빈번히 일어나는 경우, Linked List를 사용하는 것이 훨씬 functional 하다. 

(Arraylist는 element 하나를 추가 or 삭제 하기 위해 이미 만들어져 있는 모든 arraylist를 밀어내야 하기 때문에 상대적으로 큰 workload. ) 

- Due to the dynamicity and ease of insertions and deletions, they are preferred over the arrays.

Comments