A Collection in Java is a group of objects which can be ordered (List) or unordered (Set). The `Collection` interface is at the top of the hierarchy and all other classes and interfaces extend from this interface. It is located in the `java.util` package. It provides many interfaces like `Set`, `List`, `Queue`, `Deque` etc. and classes like `ArrayList`, `Vector`, `LinkedList`, `PriorityQueue`, `HashSet`, `LinkedHashSet` etc.
The `Collection` interface also extends the `Iterable` interface, which means that every collection in java must be iterable. This in turn means that a `for-each` loop can be used to fetch elements from a collection in a sequence.
These four interfaces (`Collection`, `Set`, `Queue`, `List`) along with `SortedSet`, `Deque` and `NavigableSet` form the collective `Collection` hierarchy.
`LinkedList` is one the most important `Collection` classes which provides a doubly-linked list implementation. It implements the `List`, `Deque`, `Cloneable` and `Serializable` interfaces.
Stack class, as previously mentioned classes, implements Collection interface and extends Vector class and contains five methods that treat Vector as Stack. Stack is data structure which applies principle Last In First Out (LIFO) and contains following methods:
```java
T void pop(); // 'T' represents type which is being returned as the last elemented is removed from this stack
T void peek(); // 'T' represents type which is being returned and last elemented is not being removed from this stack
T push(T element); // 'T' represents type which is being returned and last elemented is being added on this stack
boolean empty(); // returns true (if this stack is empty) of false (if this stack isn't empty)
int search(Object o) // returns position of element located on this stack
```
**Create a Stack**
Stack class is being created using following snippet of code:
```java
Stack<Integer> stackObject = new Stack<>(); // creates stack which recieves elements of Integer/int type
```
**Add elements on Stack**
```java
stackObject.push(5);
stackObject.push(2);
stackObject.push(36);
stackObject.push(4);
```
**Retrieve element from Stack**
```java
int lastElemement = stackObject.pop(); // retrieves last element pushed on top of 'stackObject' stack and REMOVES it
System.out.println(lastElemement); // prints retrieved element which is 4
lastElements = stackObject.peek(); // retrieves last element pushed on top of 'stackObject' stack and DOES NOT REMOVE it
System.out.println(lastElemement); // prints retrieved element which is 36