Shahed Abdulwahab
Posted on March 28, 2021
Collections:
Put all your eggs in one basket and watch that basket.
-Mark Twain
Collection: is a data structure for holding elements.
Collection<T>: is the highest level of the java's framework for collection.
-Two main interfaces that extend Collection<T> interface:
1.Set<T> interface:
- Does not allow duplication
- Does not impose an order on the elements
2.List<T> interface: (Allow duplication)
- Allow duplication
- Impose an order on the elements
-Two Abstract classes used (for convenience) to implement Set<T> and List<T> interface:
1.AbstractSet<T>
2.AbstractList<T>
-Another Abstract class implements Collection<T> interface which is AbstractCollection<T>, and it is a skeleton class for the Collection<T> interface
-If you want a class that implement The Set<t> interface, use the class HashSet<T>
HashSet<T>: is the concrete class implements the Set interface.
It can be used as a base class if you want to implement the Set interface.
-It is implemented using a hash table.
-If you want a concrete class that implement The List<t> interface, use
either the class ArrayList<T> or Vector<T>
They can be used as a base class if you want to implement the Set interface using your own class.
Posted on March 28, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 25, 2024