Collection
What is a Collection?
Various implementations exist based on the
List,Map, andSetinterfacesReasons for useBecause
standardized classesare provided for handling large amounts of data, you can use them conveniently without directly implementing DataStructuresUnlike arrays,
you don't need to pre-define the space for storing objects, so thenumber of objects can be determined dynamicallybased on the situationThis also improves the spatial efficiency of the program
Types of Collections
List
The
Listinterface can be directly defined and used by the user through@Override, and the representative implementation isArrayList.This is an improvement of the existing
Vector
LinkedListA data structure that stores data in a manner where each node has data and a pointer, connected in a single line
Nodes containing data are connected, and the node's pointer is responsible for the connection to the next or previous node
AdvantagesAdding/removing data at the middle of the lined-up nodes is possible in
O(1)time
DisadvantagesUnlike arrays or tree structures, searching for data at a specific position takes
O(n)time
Map
The representative implementation is
HashMapIt has a
key-valuestructure, and the specific details about Map are consistent with thehashtablein the DataStructure sectionDuplicate values are not storedbased on the key, andorder is not guaranteedTo guarantee order for keys, use
LinkedHashMap
Set
The representative implementation is
HashSet.Duplicate values for
valueare not storedIn fact, the Set data structure is simply a data structure where the value is used as the key, replacing the key in the Map's key-value structure
Likewise, order is not guaranteed, and
LinkedHashSetis used to guarantee order
Last updated