How to Make a Map or List as Thread-Safe or Synchronized Collection

Collections.synchronizedMap(new HashMap()); Collections.synchronizedList(List<T> list) In Java, if you want to make a Map or List thread-safe or synchronized, you can use the Collections.synchronizedMap and Collections.synchronizedList methods, respectively. These methods return synchronized versions of the provided Map or List. Here’s how you can use them: For a Map: java Map<String, Object> synchronizedMap = Collections.synchronizedMap(new HashMap<>()); For … Read more

What is the Difference Between the Iterator and ListIterator

Iterator : Iterator takes the place of Enumeration in the Java collections framework. One can traverse throughr the the collection with the help of iterator in forward direction only and Iterators allow the caller to remove elements from the underlying collection during the iteration with well-defined semantics ListIterator: An iterator for lists that allows one to traverse … Read more

What is Difference Between HashMap and HashSet

HashSet : HashSet does not allow duplicate values. It provides add method rather put method. You also use its contain method to check whether the object is already available in HashSet. HashSet can be used where you want to maintain a unique list. HashMap : It allows null for both key and value. It is unsynchronized. So come … Read more

What is the Properties Class

The properties class is a subclass of Hashtable that can be read from or written to a stream. It also provides the capability to specify a set of default values to be used. In Core Java, the Properties class is a class that represents a persistent set of properties, which can be loaded from or … Read more

What is Difference Between Iterator and Enumeration

Both Iterator and Enumeration are used to traverse Collection objects, in a sequential fashion. Enumeration can be applied to Vector and HashTable. Iterator can be used with most of the Collection objects. The main difference between the two is that Iterator is fail-safe. i.e,  If you are using an iterator to go through a collection … Read more