Found 7442 Articles for Java

Difference between HashTable and HashMap in Java

Rishi Raj
Updated on 21-Jun-2020 12:35:45

3K+ Views

Following are the notable differences between HashTable and HashMap classes in Java. HashTableHashMapSynchronizedHashTable is synchronized.HashMap is not synchronized.Thread SafeHashTable is thread safe.HashMap is not thread safe.Null objectsHashTable does not allows null keys or null values.HashMap allows one null key and multiple null values.PerformanceHashTable is faster.HashMap is slower than HashTable.Since Java Version1.21.5Exampleimport java.util.HashMap; import java.util.Hashtable; import java.util.Map; public class Tester {    public static void main(String args[]) {       Map map = new HashMap();       map.put("1", "One");       map.put("2", "Two");       map.put("3", "Three");       map.put("5", "Five");       ... Read More

Difference between HashTable and HashMap in Java

Rishi Raj
Updated on 21-Jun-2020 12:35:45

3K+ Views

Following are the notable differences between HashTable and HashMap classes in Java. HashTableHashMapSynchronizedHashTable is synchronized.HashMap is not synchronized.Thread SafeHashTable is thread safe.HashMap is not thread safe.Null objectsHashTable does not allows null keys or null values.HashMap allows one null key and multiple null values.PerformanceHashTable is faster.HashMap is slower than HashTable.Since Java Version1.21.5Exampleimport java.util.HashMap; import java.util.Hashtable; import java.util.Map; public class Tester {    public static void main(String args[]) {       Map map = new HashMap();       map.put("1", "One");       map.put("2", "Two");       map.put("3", "Three");       map.put("5", "Five");       ... Read More

Difference between HashMap and ConcurrentHashMap in Java

Arushi
Updated on 21-Jun-2020 12:18:12

6K+ Views

Following are the notable differences between HashMap and ConcurrentHashMap classes in Java. HashMapConcurrentHashMapSynchronizedHashMap is not synchronized.ConcurrentHashMap is synchronized.Thread SafeHashMap is not thread safe.ConcurrentHashMap is thread safe.Iterator typeHashMap iterator is fail-fast and ArrayList throws ConcurrentModificationException if concurrent modification happens during iteration.ConcurrentHashMap is fail-safe and it will never throw ConcurrentModificationException during iteration.Null valuesHashMap allows key and value to be null.ConcurrentHashMap does not allow null key/value. It will throw NullPointerException.PerformanceHashMap is faster.ConcurrentHashMap is slower than HashMap.Since Java Version1.21.5Exampleimport java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; public class Tester {    public static void main(String[] args) {       List arrayList = new ArrayList(); ... Read More

Difference between HashMap and ConcurrentHashMap in Java

Arushi
Updated on 21-Jun-2020 12:18:12

6K+ Views

Following are the notable differences between HashMap and ConcurrentHashMap classes in Java. HashMapConcurrentHashMapSynchronizedHashMap is not synchronized.ConcurrentHashMap is synchronized.Thread SafeHashMap is not thread safe.ConcurrentHashMap is thread safe.Iterator typeHashMap iterator is fail-fast and ArrayList throws ConcurrentModificationException if concurrent modification happens during iteration.ConcurrentHashMap is fail-safe and it will never throw ConcurrentModificationException during iteration.Null valuesHashMap allows key and value to be null.ConcurrentHashMap does not allow null key/value. It will throw NullPointerException.PerformanceHashMap is faster.ConcurrentHashMap is slower than HashMap.Since Java Version1.21.5Exampleimport java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; public class Tester {    public static void main(String[] args) {       List arrayList = new ArrayList(); ... Read More

Difference between ArrayList and CopyOnWriteArrayList in Java

Vikyath Ram
Updated on 21-Jun-2020 12:23:44

3K+ Views

Following are the notable differences between ArrayList and CopyOnWriteArrayList classes in Java. ArrayListCopyOnWriteArrayListSynchronizedArrayList is not synchronized.CopyOnWriteArrayList is synchronized.Thread SafeArrayList is not thread safe.CopyOnWriteArrayList is thread safe.Iterator typeArrayList iterator is fail-fast and ArrayList throws ConcurrentModificationException if concurrent modification happens during iteration.CopyOnWriteArrayList is fail-safe and it will never throw ConcurrentModificationException during iteration. The reason behind the it that CopyOnWriteArrayList creates a new arraylist every time it is modified.Remove OpearationArrayList iterator supports removal of element during iteration.CopyOnWriteArrayList.remove() method throws exception if elements are tried to be removed during iteration.PerformanceArrayList is faster.CopyOnWriteArrayList is slower than ArrayList.Since Java Version1.21.5Exampleimport java.util.Iterator; import java.util.concurrent.CopyOnWriteArrayList; public class Tester { ... Read More

Difference between ArrayList and CopyOnWriteArrayList in Java

Vikyath Ram
Updated on 21-Jun-2020 12:23:44

3K+ Views

Following are the notable differences between ArrayList and CopyOnWriteArrayList classes in Java. ArrayListCopyOnWriteArrayListSynchronizedArrayList is not synchronized.CopyOnWriteArrayList is synchronized.Thread SafeArrayList is not thread safe.CopyOnWriteArrayList is thread safe.Iterator typeArrayList iterator is fail-fast and ArrayList throws ConcurrentModificationException if concurrent modification happens during iteration.CopyOnWriteArrayList is fail-safe and it will never throw ConcurrentModificationException during iteration. The reason behind the it that CopyOnWriteArrayList creates a new arraylist every time it is modified.Remove OpearationArrayList iterator supports removal of element during iteration.CopyOnWriteArrayList.remove() method throws exception if elements are tried to be removed during iteration.PerformanceArrayList is faster.CopyOnWriteArrayList is slower than ArrayList.Since Java Version1.21.5Exampleimport java.util.Iterator; import java.util.concurrent.CopyOnWriteArrayList; public class Tester { ... Read More

Deque interface in Java

Fendadis John
Updated on 21-Jun-2020 12:26:34

460 Views

java.util.Deque interface is a subtype of java.util.Queue interface which supports insertion and removal of elements at both ends.Interface Declarationpublic interface Deque extends QueueArrayDeque ClassThe java.util.ArrayDeque class provides resizable-array and implements the Deque interface. Following are the important points about Array Deques −Array deques have no capacity restrictions so they grow as necessary to support usage.They are not thread-safe; in the absence of external synchronization.They do not support concurrent access by multiple threads.Null elements are prohibited in the array deques.They are faster than Stack and LinkedList.This class and its iterator implement all of the optional methods of the Collection and Iterator ... Read More

Deque interface in Java

Fendadis John
Updated on 21-Jun-2020 12:26:34

460 Views

java.util.Deque interface is a subtype of java.util.Queue interface which supports insertion and removal of elements at both ends.Interface Declarationpublic interface Deque extends QueueArrayDeque ClassThe java.util.ArrayDeque class provides resizable-array and implements the Deque interface. Following are the important points about Array Deques −Array deques have no capacity restrictions so they grow as necessary to support usage.They are not thread-safe; in the absence of external synchronization.They do not support concurrent access by multiple threads.Null elements are prohibited in the array deques.They are faster than Stack and LinkedList.This class and its iterator implement all of the optional methods of the Collection and Iterator ... Read More

CopyOnWriteArrayList Class in Java

karthikeya Boyini
Updated on 19-Jun-2020 14:41:11

5K+ Views

Class declarationpublic class CopyOnWriteArrayList    extends Object implements List, RandomAccess, Cloneable, SerializableCopyOnWriteArrayList is a thread-safe variant of ArrayList where operations which can change the ArrayList (add, update, set methods) creates a clone of the underlying array.CopyOnWriteArrayList is to be used in a Thread based environment where read operations are very frequent and update operations are rare.Iterator of CopyOnWriteArrayList will never throw ConcurrentModificationException.Any type of modification to CopyOnWriteArrayList will not reflect during iteration since the iterator was created.List modification methods like remove, set and add are not supported in the iteration. This method will throw UnsupportedOperationException.null can be added to the ... Read More

CopyOnWriteArrayList Class in Java

karthikeya Boyini
Updated on 19-Jun-2020 14:41:11

5K+ Views

Class declarationpublic class CopyOnWriteArrayList    extends Object implements List, RandomAccess, Cloneable, SerializableCopyOnWriteArrayList is a thread-safe variant of ArrayList where operations which can change the ArrayList (add, update, set methods) creates a clone of the underlying array.CopyOnWriteArrayList is to be used in a Thread based environment where read operations are very frequent and update operations are rare.Iterator of CopyOnWriteArrayList will never throw ConcurrentModificationException.Any type of modification to CopyOnWriteArrayList will not reflect during iteration since the iterator was created.List modification methods like remove, set and add are not supported in the iteration. This method will throw UnsupportedOperationException.null can be added to the ... Read More

Advertisements