The Java Collections Framework is a collection of interfaces and classes which helps in storing and processing the data efficiently. This framework has several useful classes which have tons of useful functions which makes a programmer task super easy. I have written several tutorials on Collections and below are the links of those. All the tutorials are shared with examples and source codes to help you understand better.
Collections Framework hierarchy
A List is an ordered Collection (sometimes called a sequence). Lists may contain duplicate elements. Elements can be inserted or accessed by their position in the list, using a zero-based index.
- How to loop ArrayList
- How to get sublist of an ArrayList
- ArrayList Sorting
- Find length of an ArrayList
For more tutorials on ArrayList, refer: ArrayList tutorials
- Loop LinkedList
- Search elements in LinkedList
- Append elements of a list to LinkedList
- push() and pop() in LinkedList
- Iterate a LinkedList in Reverse order
For more tutorials on LinkedList, refer: LinkedList tutorials
For more tutorials on Vector, refer: Vector tutorials
A Set is a Collection that cannot contain duplicate elements. There are three main implementations of Set interface: HashSet, TreeSet, and LinkedHashSet. HashSet, which stores its elements in a hash table, is the best-performing implementation; however it makes no guarantees concerning the order of iteration. TreeSet, which stores its elements in a red-black tree, orders its elements based on their values; it is substantially slower than HashSet. LinkedHashSet, which is implemented as a hash table with a linked list running through it, orders its elements based on the order in which they were inserted into the set (insertion-order).
For more tutorials on HashSet, refer: HashSet tutorials
A Map is an object that maps keys to values. A map cannot contain duplicate keys. There are three main implementations of Map interfaces: HashMap, TreeMap, and LinkedHashMap.
HashMap: it makes no guarantees concerning the order of iteration
TreeMap: It stores its elements in a red-black tree, orders its elements based on their values; it is substantially slower than HashMap.
LinkedHashMap: It orders its elements based on the order in which they were inserted into the set (insertion-order).
- HashMap Iterator example
- Sort HashMap by Keys and Values
- Check if particular key exists in HashMap
- Check if particular value exists in HashMap
For more tutorials on HashMap, refer: HashMap tutorials
Both Iterator and ListIterator are used to iterate through elements of a collection class. Using Iterator we can traverse in one direction (forward) while using ListIterator we can traverse the collection class on both the directions(backward and forward). To know more differences between these two refer this article: Difference between Iterator and ListIterator.
Comparable and Comparator
These interfaces are used for sorting objects of user defined class (custom class).