Data Structure
Collection
A collection is an object that contains many elements. You can put duplicate elements to some collections. And some collections have ordered elements.
Collection Interfaces
java.util.Set
java.util.List
java.util.Queue
java.util.Deque
java.util.Map
interface | hash table | array | balanced tree | linked list | hash + linked |
---|---|---|---|---|---|
Set | HashSet | ArraySet | TreeSet | LinkedHashSet | |
List | ArrayList | LinkedList | |||
Map | HashMap | ArrayMap | TreeMap | LinkedHashMap |
class | ordered | sorted | duplicate values | null keys | null elements |
---|---|---|---|---|---|
HashSet | X | X | X | O | |
ArraySet | O | X | X | O | |
TreeSet | X | O | X | X | |
LinkedHashSet | O | X | X | O | |
ArrayList | O | X | O | O | |
LinkedList | O | X | O | O | |
HashMap | X | X | O | O | O |
ArrayMap | X | X | O | O | O |
TreeMap | X | O | O | X | O |
LinkedHashMap | O | X | O | O | O |
Concurrent Collections
ConcurrentHashMap
is normally preferable to a synchronizedHashMap
ConcurrentSkipListMap
is normally preferable to a synchronizedTreeMap
CopyOnWriteArrayList
is preferable to a synchronizedArrayList