Collection
is a storage for individual values, whereas a Map
is a key-value storage. This fundamental difference leads to different methods in these interfaces. To put it simply, they have different method signatures such as put
for Map and add
for Collection.The
Collection
itself is divided into three main groups, each corresponding to a specific interface:List
– Ordered tuples that can contain duplicates and allow index-based (random) access;Queue
– Typically FIFO collections, which implies adding/removing elements from the end. There is a sub-interface calledDeque
– double-ended queue adapted for manipulation on both ends;Set
– Collections that are not necessarily ordered and contain unique (fromequals
perspective) elements .
A
HashMap
can be converted into a form of Collection
by invoking methods like keySet()
, entrySet()
, or values()
.