Difference between Set and Array List? (java)
set interface: 1. Sets can't contain duplicate values (just like a mathematical set),
2. Sets inherits collection and adds method to avoid duplications
There are 3 Set implementations:
- uses hash table/ hashmap internally to store values,
- it is very fast compared to other two set implementations,
- it will not have any order while reading,
- it will not contain any duplicate elements,
- it is not synchronized by default
- will not guarantee any order over time
- iteration order/ reading order is not predictable.
the order in which u entered may differ while reading.
- internally uses red-black tree to store the values,
- it will maintain ascending order
- it is slowest of all other 2 set implementations.
- rest of the properties remain same
3. linkedhash set
- internally uses hash table with linked list to store values.
- same as hashset but order in which user entered will be persisted.
- it is neither fast nor slow comparatively.
- rest of the properties remain same.
- it is ordered (maintains the insertion order) & may contain duplicate values
- inherits from collection, and add functions for indexof, search functionalities.
1. arraylist (better performance) - same as vector ..
2. linked list (better performace in some circumstances)
Back To Top