7.
A Stack is a linear data structure where you can only add or remove items from the top. It
follows Last In, First Out (LIFO) rule — that is last item you put in the stack will be the first one
you take out.
8.
Set is a collection in Java that does not allow duplicate elements. It is a part of the Java
Collections Framework and is used when we want to store unique items only.
1. HashSet
✅ Definition:
HashSet stores elements using a hash table.
It does not maintain any order (neither insertion nor sorted).
Allows null values (only one null element).
2. LinkedHashSet
✅ Definition:
LinkedHashSet is similar to HashSet but maintains insertion order.
Elements are stored in the order they were added.
Useful when order matters and duplicates need to be avoided.
3. TreeSet
✅ Definition:
TreeSet stores elements in sorted (natural) order.
It does not allow null elements.
Automatically maintains elements in ascending order.
13.
In Java, a PriorityQueue is a part of the java.util package and automatically maintains elements
in sorted order (natural order for numbers). Internally, it uses a min-heap to store elements.
By using PriorityQueue, we can insert a set of integers and retrieve them in ascending sorted
order by polling the elements one by one.