Array/ Array list/ Linked list
How can we eradicate duplicated value in array?
1. Set
Set
does not allow duplication- convert array into
set
π‘ Set https://soheeparklee.github.io/posts/DS-list_set_map/
2. For loop
- λ°°μ΄μ λλ©΄μ μ€λ³΅λλ κ° μμ
3. Array.sort
- λ°°μ΄μ μ€λ¦μ°¨μ/λ΄λ¦Όμ°¨μμΌλ‘ μ λ ¬
- μμ μλ κ°λΌλ¦¬ λΉκ΅ν΄μ κ°μΌλ©΄ μμ
4. Stream API
- use stream to delete duplicated value
- stream API is added from
JAVA 8
Array π Array List π Linked List
βοΈ Array
- ππ» can access directly with index to element
- time complexity: O(1)
- ππ» need to fix size while creating
βοΈ Array List(Array)
- use dynamic array to store data
- ππ» dynamic
- ππ» has list, can access directly
- ππ» fast in searching data
- insertion, deletion slow
Why slow in insertion, deletion?
λ°μ΄ν° μΆκ° λ° μμ λ λ°μ΄ν°λ₯Ό μ¬ν λΉνλ€.
thus, insertion and deletion slower than array
βοΈ Linked List(Node)
- use doubly linked list to store data
- ππ» dynamic: do not need to fix size
- ππ» insertion, deletion easy
- has address that saves the location of previous, next nodes
- for insertion, deletion, just need to change value of previous, next node
- ππ» cannot access directly, need to search from head
π Q&A
Why use array, instead of linked list?
fast in search
can access element using index
When to use array, when to use linked list?
array: search
linked list: insertion, deletion
π‘ Reference
https://soheeparklee.github.io/posts/JAVA_list/
https://soheeparklee.github.io/posts/JAVA_collectionFramework/
This post is licensed under CC BY 4.0 by the author.