Collections in java are used in almost every enterprise application. Java Collections framework consists of interfaces and classes which helps in storing and processing the data efficiently. Java Collections Tutorial will look into each of the classes.
Read Also : Collections in Java Interview Questions
1. Collection Interface
2. List Interface
3. Set Interface
4. Map Interface
5. Queue Interface
What is Java Collections Framework?
Java Collections are similar to containers that consists of multiple items in a single unit. for e,g. collections of candies, list of names etc. Java Collections framework provides unified architecture for manipulating and representing Collections.
Benefits of Java Collections Framework
Read Also : Collections in Java Interview Questions
Java Collections Interfaces and Classes
- ArrayList Class
- LinkedList Class
- Vector Class
- HashSet Class
- TreeSet Class
- LinkedHashSet Class
- HashMap Class
- TreeMap Class
- LinkedHashMap Class
- Hashtable Class
- Priority Queue Class
What is Java Collections Framework?
Java Collections are similar to containers that consists of multiple items in a single unit. for e,g. collections of candies, list of names etc. Java Collections framework provides unified architecture for manipulating and representing Collections.
Benefits of Java Collections Framework
- It improves program quality and speed.
- Increases the chances of reusability of software.
- Decreases programming effort.
Java Collection Interfaces and Classes
1. Collection Interface
This is the root interfaces of the java collection classes hierarchy.A Collection represents a group of objects known as its elements.There is no direct implementation of Collection interface.It has very useful methods like size(),isEmpty(),contains(),add(),remove(),iterator() etc.2. List Interface
List interface is an ordered collection meaning you can access the elements of a List in specific order. and by an index too. It can contain duplicate elements.Since List is an interface you need to provide a concrete implementation of the interface in order to use it.2.1 ArrayList Class
ArrayList in Java tutorials are as follows:ArrayList Basics
ArrayList Sorting
- Sort ArrayList in Ascending Order
- Sort ArrayList in Descending Order
- Sort ArrayList of Objects using Comparable and Comparator
ArrayList Add/Remove
- Add element to ArrayList
- Add element at Particular Index of ArrayList
- Append Collection elements to ArrayList
- Insert all the Collection elements at the Specified Position in ArrayList
- Remove element from Specified Index in ArrayList
- Remove specified element from ArrayList
ArrayList Internal Working
ArrayList Conversions
- Convert HashSet to ArrayList in java
- Convert Array to ArrayList
- Convert LinkedList to ArrayList
- Convert ArrayList to String Array
Differences
- ArrayList vs Array
- ArrayList vs Vector
- ArrayList vs LinkedList
- ArrayList vs HashMap
- ArrayList vs HashSet
- ArrayList vs CopyOnWriteArrayList
Other Tutorials
2.2 LinkedList Class
LinkedList in java tutorials are as follows :
2.3 Vector Class
Vector is rarely used in the real world. It implements List interface.It maintains insertion order.It is synchronized that's why it gives poor performance in searching, adding, delete and update of the elements.
3. Set Interface
Set interface stores unique elements meaning each element can only exists once in a Set.It is unordered meaning it makes no guarantee about the sequence of elements once you iterate them.Since Set is an interface you need to provide a concrete implementation of the interface in order to use it.3.1 HashSet Class
HashSet in java tutorials are as follows:
Basics
Conversions
Differences
More Interview Questions
3.2 TreeSet Class
TreeSet in java tutorials are as follows:
3.3 LinkedHashSet Class
LinkedHashSet implements Set interface. LinkedHashSet unlike HashSet maintains insertion order i.e elements are placed in the order they are inserted. LinkedHashSet should be preferred if you want a unique collection of objects in an insertion order.
4. Map Interface
Map interface represents a mapping between a key and a value.The Map interface does not belongs to the Collection interface hierarchy, so, it behaves a bit different from the rest of the collection types.Map is an interface you need to provide a concrete implementation of the interface in order to use it.4.1 HashMap Class
HashMap in java tutorials are as follows:
HashMap Basics
- HashMap in Java
- How to iterate HashMap in Java
- Get Size of HashMap
- How to check if HashMap is Empty or not
- Sort HashMap by Keys and Values
- Remove Key-Value Mapping from HashMap
- Remove all Key-Value Pairs from HashMap
Differences
- HashMap vs Hashtable
- HashMap vs ConcurrentHashMap
- HashMap vs HashSet
- HashMap vs ArrayList
- HashMap vs TreeMap
- HashMap vs WeakHashMap
- HashMap vs IdentityHashMap
Internal Working
Serialize/Synchronize
Get/Search
Other Tutorials
4.2 TreeMap Class
TreeMap in java tutorials are as follows:
4.3 LinkedHashMap Class
LinkedHashMap is a Hashtable and linked list implementation of the Map interface, with predictable iteration order. This class is different from HashMap and TreeMap i.e it maintains the insertion order. HashMap does not maintain any order and TreeMap sort the entries in ascending order of keys.4.4 Hashtable Class
Hashtable implements hash table which maps keys to values. Any non null object can be used as a key or as a value.
5. Queue Interface
Queue is an interface you need to provide a concrete implementation of the interface in order to use it. Queue typically but do not necessarily order elements in FIFO(first in first out) manner. Every Queue implementation must specify its ordering properties.5.1 PriorityQueue Class
PriorityQueue class is based on a priority heap. The elements of the priority queue are ordered according to their natural ordering. A priority queue relying on natural ordering does not permit insertion of non-comparable objects.
Other Tutorials in Java Collections
Comparator vs Comparable
Fail-fast Iterator vs Fail-safe iterator
Other Tutorials in Java Collections
Comparator vs Comparable
Fail-fast Iterator vs Fail-safe iterator