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

Deque interface in java

Deque interface: Deque interface represents a double-ended-queue. A deque represents a linear collection of elements that support insertion, retrieval and removal of elements at both ends. Deques can be used both as FIFO (first-in, first-out) and LIFO (last-in, first-out). In a deque all new elements can be inserted, retrieved and removed at both ends. Commonly … Read more

Queue interface in java

Queue interface: Queue represents a collection for holding elements prior to processing. Note: Queue declares its own methods in addition with methods declared in Collection interface. Commonly used methods of Queue Interface: 1. add(Object obj): Inserts the specified element into this queue. Returns true if queue changed after the operation otherwise returns false. Syntax: public … Read more

SortedMap interface in java

SortedMap interface: SortedMap interface extends Map interface. It maintains its entries in ascending key order. Commonly used methods of SortedMap interface: 1. comparator(): Returns comparator for this sorted map. It returns null if the natural ordering is used for this map. Syntax: public Comparator comparator(). 2. firstKey(): Returns the first key in this map. Syntax: public Object firstKey ( ). … Read more

Map.Entry interface in java

Map.Entry interface: Map.Entry interface provides the facility to work with a map entry. The entrySet( ) method of the Map interface returns the set of map entries i.e. set of Map.Entry objects. Commonly used methods of Map.Entry interface: 1. equals(Object obj): Returns true if specified object is equals to this map otherwise returns false. Syntax: … Read more