TCS Java Interview Questions

In this post, we covered the TCS java interview questions. The candidate got asked about the Java 8 Stream operations where he was given two list and he has to do concatenation of two lists. After that he has to find the unique elements from the list and finally he Read more…

How Generics Work in Java?

Let’s examine how generics work in Java. Also, we will look at how generics is a compile-time feature. To demonstrate this concept, we are going to mix generic and non-generic types. But in the real world never mix these two types. Let’s try to mix the generic and non-generic types Read more…

Autoboxing with Generics in Java

In this post, we are going to look at how autoboxing works with Generics in Java. Autoboxing is a feature that got introduced in Java 1.5 and it plays a very important role while using generics. As we know generic collections can only hold object types. But Java also has Read more…

Why Generics in Java?

Generics got introduced in Java SE 5.0, but the question is why use generics in the first place? In this tutorial, we are going to look at some of the problems that developers faced before generics. Before generics, it is the developer’s responsibility to add the correct types of elements Read more…

HashMap clear() Method in Java

The clear() method of HashMap removes all the mappings from the map. After a call to the clear method, the HashMap becomes empty and the size of a map effectively becomes zero. There is no way to get back the elements once the clear operation is complete. This method is Read more…

HashMap keySet() Method in Java

The keySet() method of HashMap returns a set of keys contained in it. Any changes to the map also modify the returned set and vice versa. Removing value from the set also removes the associated key/value pair from the Hashmap. There is no provision to do add operations on the Read more…

HashMap isEmpty() Method in Java

The isEmpty() method of HashMap checks if the map contains any key/value pairs. It returns true if the map does not contain any entries. More formally, it returns true if the size of the HashMap is equal to zero. If the size of the HashMap is greater than zero then Read more…

HashMap size() Method in Java

The size() method of HashMap returns the number of key-value entries present in the map. When we create the HashMap its size is zero. This size of the HashMap increases as we add key-value pairs and reduce as we remove the entries. After clearing the HashMap the size again becomes Read more…

HashMap remove() Method in Java

The remove(K key) method of HashMap removes the entry for the specified key from the map. It returns the value associated with the key. To remove a specific key-value combination from the HashMap use the remove(K key, V value) method. The remove(key, value) method removes the entry only when both Read more…

HashMap entrySet() Method in Java

The entrySet() method of HashMap returns the set view of the entries in this map. Syntax Set<Entry<K, V>> entrySet() Parameters It does not take any parameters. Return Value It returns the set of entries Program Output Key-Value entries in map: [101=John, 102=Adam, 103=Ricky, 104=Chris]