TreeMap in java

TreeMap: TreeMap extends AbstractMap class and implements the NavigableMap interface. It contains the elements in key-value pair form. It maintains ascending order for its elements. It is not allowed duplicate keys. Note: A TreeMap can have only one null key but can have multiple null values. It is non-synchronized. TreeMap class declaration: public class TreeMap<K,V> extends … Read more

LinkedHashMap in java

LinkedHashMap: LinkedHashMap extends the HashMap class and implements the Map interface. It contains the elements in key-value pair form. It maintains insertion order for its elements. It does not allow duplicate keys. A LinkedHashMap can have only one null key and multiple null values. Its initial default capacity is 16 with a load factor of … Read more

HashMap in java

HashMap: HashMap extends AbstractMap class and implements the Map interface. It contains the elements in key-value pair form. It does not maintain any order for its elements. It is not allowed duplicate keys. A HashMap can have only one null key and multiple null values. No order is maintained by the HashMap class. It is … Read more

LinkedList in java

The LinkedList class extends AbstractSequentialList and implements the List and Deque interface. It uses a linked list data structure to store elements. It can contain duplicate elements. It is not synchronized. Note: It does not provide a random access facility. No shifting needs to occur in the Java LinkedList class, thus manipulation is fast. Doubly … Read more

ArrayList in java

The ArrayList class extends AbstractList and implements the List interface. It uses dynamic arrays for storing elements. It maintains insertion order. ArrayList can contain duplicate elements. It is not synchronized. Note: ArrayList provides the facility of random access because it is index-based. A lot of shifting needs to occur if any element is removed from … Read more

TreeSet in java

TreeSet extends AbstractSet and implements the NavigableSet interface. It maintains ascending order for its elements i.e. elements will be in sorted form. Just like HashSet, the Java TreeSet class contains unique elements only. The access and retrieval times of the TreeSet class are very fast. It does not give access to the null element. It maintains the ascending … Read more

LinkedHashSet in java

LinkedHashSet extends HashSet and implements the Set interface. It maintains insertion order for its elements. There are certain important points about the  LinkedHashSet class which is required to understand while using the LinkedHashSet class. Similar to the HashSet class, the LinkedHashSet class can also hold the unique elements only. It facilitates all optional set operations. It is non-synchronized. … Read more

HashSet in java

HashSet: HashSet extends AbstractSet and implements the Set interface. It does not maintain any order for its elements. It uses a hash table for storage. The elements are stored by the HashSet class using the hashing mechanism. Only unique elements are allowed by the HashSet class. Null values are allowed by the HashSet class. It … Read more

Collection classes in java

Collection classes: Collection classes are the concrete implementations of the collection interfaces. Collection classes are given below: 1. HashSet: HashSet extends AbstractSet and implements the Set interface. It not maintains any order for its elements. It uses hash table for storage. 2. LinkedHashSet: LinkedHashSet extends HashSet and implements the Set interface. It maintains insertion order for its elements. 3. TreeSet: TreeSet extends AbstractSet … Read more

Enumeration interface in java

Enumeration Interface: It provides the methods to get a series of elements from a collection of object taking one at a time. Commonly used methods of Enumeration interface: 1. hasMoreElements(): It returns true if more elements are left to iterate otherwise returns false. Syntax: public boolean hasMoreElements() 2. nextElement(): It returns the next object of … Read more