In-Built Data Structure that might entice you(Java Edition)
While solving problems and developing algorithms for either programming questions or real-world problems, we feel like if we could get something readily available or pre-coded we could save our time or more importantly we have to work less.
So here we will look at data structures that might save you loads of labour.
1. LinkedHashMap
When to use it: When you have to implement a feature where the order of insertion is prioritized. Like if you want to implement an LRU cache.
What it is: It is a simple HashMap but elements in it can be accessed in the order of insertion. So maintaining order is an additional feature.
2. TreeMap
When to use it: When you want your entries in a sorted(order) ascending.
What it is: It is also a HashMap with the additional feature of implementing Red-Black Tree at the backend thereby providing an efficient and smooth data structure.
3. NavigableMap
When to use it: Just to ease your work easy navigable functions.
What it is: It is an extension of the SortedMap Interface yet you can use it to form sub-maps.
4. ConcurrentHashMap
When to use it: When you are operating on distributed systems.
What it is: It is a HashMap that is thread-safe and implements several features that help in multi-threading of hashmaps. As it is thread-safe it operates faster and more smoothly.
5. HashSet
When to use it: When you want to save only keys and not the entire pair.
What it is: It is a set implementation which is done by a HashMap but only keys are stored rather than pair and order is not maintained.
6. vector
When to use it: When you want a randomly accessible data structure but you are unaware of its size.
What it is: Although ArrayList is more frequent in java yet vector can also be used but its drawback is that it is not thread-safe. Moreover, it can store different data types at different indexes.