Copy Constructor in Java

What is Copy Constructor Sometimes a programmer wants to create an exact but separate copy of an existing object so that subsequent changes to the copy should not alter the original or vice versa. This is made possible using the copy constructor. A copy constructor is a constructor that creates a new object using an […]

Read More

TreeSet in Java

What is TreeSet A NavigableSet implementation based on a TreeMap. The elements are ordered using their natural ordering, or by a Comparator provided at set creation time, depending on which constructor is used. Like HashSet, TreeSet also implements Set interface. Like HashSet, TreeSet allows to store only unique elements in their objects. HashSet is much […]

Read More

HashSet in Java

What is HashSet HashSet extends AbstractSet and is an implementation of Set interface. HashSet also implements Serializable and Cloneable interfaces. HashSet is backed by hash table(actually HashMap instance), i.e., the HashSet uses hash table(HashMap) to store collection elements. Like HashMap, it allows null only one element.

Read More

CopyOnWriteArrayList in Java

What is CopyOnWriteArrayList CopyOnWriteArrayList is a concurrent Collection class introduced in Java 5 Concurrent API. It implements List interface like ArrayList, Vector and LinkedList but it is a thread-safe collection and it achieves its thread-safety in a slightly different way than Vector or other thread-safe collection class. CopyOnWriteArrayList creates a fresh copy of the underlying […]

Read More

JUnit Code Coverage

JaCoCo is quite a new maven plug-in that provides the JaCoCo runtime agent to your tests and allows basic report creation. Currently it supports instruction, branch, line, method and class coverage which is pretty enough you can expect from this kind of tool. Additionally, it can measure and report cyclomatic complexity for methods and summarize […]

Read More

TreeMap in Java

What is TreeMap It is a Red-Black tree based NavigableMap implementation. Like HashMap it contains only unique elements. Unlike HashMap it cannot have null key but like HashMap it can have multiple null values. The map is sorted according to the natural ordering (ascending order) of its keys, or by a Comparator provided at map […]

Read More

LinkedHashMap in Java

What is LinkedHashMap A LinkedHashMap like HashMap is a simple yet powerful way to store and get data. Unlike HashMap, LinkedHashMap is based on HashTable and Linked list implementation of the Map interface and stores items as key/value pairs. Like HashMap, LinkedHashMap permits only unique keys. It also permits only one null key (whereas HashTable […]

Read More

HashMap in Java

What is HashMap A HashMap is a simple yet powerful way to store and get data. HashMap is based on HashTable implementation, that implements the Map interface and stores items as key/value pairs. HashMap permits only unique keys. It also permits only one null key (whereas HashTable does not allow any null key) but may […]

Read More

ConcurrentHashMap in Java

Though we have thread-safe collections classes like HashTable, Synchronized Map, which can be used in multi-threaded environment but there are significant differences between them, which arise from the fact that how they achieve their thread-safety. All methods of Hashtable are synchronized which make them quite slow due to the number of thread increases. Synchronized Map […]

Read More

1 2