2014년 6월 30일 월요일

Difference between Set, List and Map in Java

Set provides uniqueness guarantee i.e.g you can not store duplicate elements on it, but it's not ordered.
List is an ordered Collection and also allowes duplicates.
Map is based on hashing and stores key and value in an Object called entry. It provides O(1) performance to get object, if you know keys, if there is no collision.

Another key difference between Set, List and Map are that Map doesn't implement Collection interface, while other two does.

Popular impelmentation of Set is HashSet, of List is ArrayList and LinkedList, and of Map are HashMap, Hashtable and ConcurrentHashMap.


-------------------------------------------------------------------
- Set : 중복이 불가해서 고유성은 보장되지만, 순서 유지 불가능
- List : 순서가 유지되고, 중복 가능
- Map : key와 value로 entry라 불리는 Object를 저장하고 찾는다. 키를 알고 있고, 충돌이 없다면, object를 얻는데 performance가 가장 좋다


- Set, List는 Collection 인터페이스를 구현했지만, Map은 아니다.

- 구현체 중 많이 쓰이는것
> Set : HashSet
> List : ArrayList, LinkedList
> Map : HashMap, Hashtable, ConcurrentHashMap.



출처 :
http://javarevisited.blogspot.kr/2011/11/collection-interview-questions-answers.html

댓글 없음:

댓글 쓰기