Collection Interview Questions

How can we make Hashmap synchronized? HashMap can be synchronized by Map m = Collections.synchronizedMap(hashMap); Question 13 : What are IdentityHashMap and WeakHashMap? IdentityHashMap : IdentityHashMap is similar to HashMap except that it uses reference equality when comparing elements. IdentityHashMap class is not a widely used Map implementation. While this…

Continue reading

Producer Consumer Example

The producer-consumer problem (also known as the bounded-buffer problem) is a classic Java Example of a multi-process synchronization problem. The problem describes two processes, the producer and the consumer, who share a common, fixed-size buffer used as a queue. The producer’s job is to generate a piece of data, put…

Continue reading

Java Collections – Stack

Stack is a subclass of Vector that implements a standard last-in, first-out stack(LIFO). Stack only defines the default constructor, which creates an empty stack. Stack stack = new Stack(); Stack includes all the methods defined by Vector, and adds several of its own.         boolean empty() Tests…

Continue reading

Java Collections – Deque

Deque implementation: The java.util.Deque interface is a subtype of the java.util.Queue interface. It represents a queue where you can insert and remove elements from both ends of the queue. Thus, “Deque” is short for “Double Ended Queue” and is pronounced “deck”, like a deck of cards. Being a Queue subtype…

Continue reading

Java Collections – Queue

Queue (Interface):- Child interface of collection. If we want to represent a group of individual object prior to processing then we should go for queue. For Eg:- Before sending a mail, for all mail ids  same order mails should be delivered.(FIFO-FIRST IN FIRST OUT). For this requirement queue concept is…

Continue reading

Fail Fast Vs Fail Safe Iterator

What is Concurrent Modification ? When one or more thread is iterating over the collection, in between, one thread changes the structure of the collection (either adding the element to the collection or by deleting the element in the collection or by updating the value at particular position in the…

Continue reading

Collection

Need of collection frame work? Usually we declare the variables according to our requirement. But it is difficult to declare huge number of values. So we shifted to arrays. For eg.  Student[]s= new student[1000]; The biggest advantage of arrays is huge number of value can be stored in one variable.…

Continue reading