Java Hungry

How Remove Method Works Internally in HashMap with Example

This is one of the new hottest  technical java interview  question, how remove method works  internally in hashmap or explain the internal implementation of remove method in hashmap. Thanks to one of the Java Hungry readers Sarika , for pointing out this question. If you do not know how hashmap works in java , then please read it before reading this post.

Read Also :   How ConcurrentHashMap works internally in Java

How Remove method works internally in Java

 In HashMap we need key and value to add element to the HashMap object.
So if we add element to the HashMap object then the code will be like this :

public class JavaHungry {
    public static void main(String[] args)
        HashMap hashmap = new HashMap();
        hashmap.put("Java", 1);
        hashmap.put("Hungry" , 2);
        hashmap.put("Blogspot" , 3);

        Iterator iteratorobject = hashmap.keySet().iterator(); 
              String hashmapkey =; 

It will print the result :  [321]

Best books for Learning Java : Must read

We are sharing the best books for learning Java . If you are new to the java world then you should not miss out these books .Most of the readers find it hard to learn java at the beginning.  So if you read these books thoroughly and understand the concepts , then I am sure you will not have any trouble in java interviews or any competition involving java.
Best books for learning java are read by almost every Java developer , these are the books which makes you different and give an extra edge against the students who have just the basic knowledge of java .

Read Also :    How to convert String to int in java without using ParseInt() method :Code with Example

Book we recommend to start your java learning or java book for beginner is :

Best books for learning java :  1  -  Head First Java  

best books for learning java : head first javaThis is the first door   to start moving your feet towards mastery in java . The best thing about this book is  image visualization . Every concept of java is explained with the help of  images and diagrams . Thus it becomes very easy for the java beginners to understand concept through images along with examples . I find it really enjoyable to start learning java with this book . Kathy siera and bert bates , the writers of this book  are one of the most respected people in the Java community. They have worked together in Sun (Company later acquired by Oracle) and  has contributed questions in setting papers for the professional certification program like Oracle certified java professional (OCJP). They have explained the concepts in the best possible way .There are exercises like fill in the blanks , match the following at the end of every chapter ,so in  that way ,you can implement whatever you have learned about the concept.  Thus ,  in beginning ,either 1 or 2(below) should be your best books for learning java.                          

Difference between Comparable and Comparator Interface along with Example In Java : Collection

Difference between Comparable and Comparator with example is probably one of the most important question on java collections topic ,which are  mostly used in Java as the sorting tools for the Collection classes such as the Arraylist ,Hashset ,etc.

 First we need to understand what are comparable and comparator interfaces .

Read Also :    Difference between  ArrayList and Vector

What is Comparable Interface ? Where we use it ?

Comparable Interface : Comparable is an public interfaces which is used to impose an natural ordering (if numbers then 1,2,3 or in alphabetical order   'a','b','c' ) of the class that implements it.
Now here the total ordering defines as the natural ordering which means in JVM that when we compare two objects using the comparable interfaces they are actually compared through their ASCII values which is the natural ordering. This means that the comparable by default uses the sorting technique of JVM i.e.  Of sorting by the ASCII values.Lists (and arrays) of objects that implement this interface can be sorted automatically by Collections.sort (and Arrays.sort).

What is Comparator Interface ? Where we use it ?

Comparator Interface : A comparison function, which is used to impose ordering on some collection of objects. To allow precisely control over the sort order , Comparators can be passed to a sort method (e.g Collections.sort()). Certain type of data structures such as TreeSet or TreeMap can also be sorted using Comparator.

Read Also :     How Hash Map works in Java

Differences between the Comparator and the Comparable interfaces :

1.  Sort sequence :  In comparable ,Only one sort sequence can be created while in comparator many sort sequences can be   created .