【Data Structures】 1. Collection,
【Data Structures】 1. Collection,
Collections in Java that are called the Java Collections Framework are a set of interfaces and classes that are available for you to use in the java.util. package
Java Collections Framework:
Interface | Implementation |
List | ArrayList, LinkedList |
Set | HashSet, TreeSet |
Map | HashMap, TreeMap |
Set extends Collection but forbids duplicates
List extends Collection also and allows duplicates and introduces positional indexing
Map extends neither Set nor List. Map is a collection of pair (key, value). Map cannot contain duplicate keys
General-Purpose Data Structure
1. Arrays
The amount of data is reasonably small
The amount of data is predictable in advance
2. Linked Lists
The amount of data is comparatively small
The amount of data cannot be predicted in advance
When data will frequently be inserted and deleted
3. Binary Search Trees
Generally, a binary search tree is the first structure to consider when arrays and linked lists prove too slow
It provides fast insertion, searching, and deletion
When you are sure that the input data will arrive in random order (Ordered data as an input can reduce its performance, no better than a linked list)
4. Hash Tables
Generally, the fastest, expecially for search, insertion, and deletion
Not sensitive to the order in which data is inserted
Requires additional memory
Performance is affected by initial capacity and load factor
Special-Purpose Data Structure
1. Stack
Used when a program needs to access only the last data item inserted (LIFO)
2. Queue
Used when a program needs to access only the first item inserted (FIFO)
3. Priority Queue
Used when the only access desired to the data item with the highest priority
Can be implemented using an array, a linked list or a heap. When speed is important, a heap is a better choice
Common operations:
Addition (Insertion), Removal (Deletion), Sorting, Searching, Iteration (Traversal), Copying (Cloning)
相关文章
- 暂无相关文章
用户点评