UrbanPro

Learn Java Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Can Anybody explain Internal code of HashMap?

Asked by Last Modified  

15 Answers

Learn Java

Follow 0
Answer

Please enter your answer

Tutor

Now we can synchronize map also by using collections. Synchronize method need to pass map Object as parameter...
Comments

Java Tutor 6 years of IT Industry Experience

HashMap works on HashCode and Equals Concept
Comments

HashMap works on the principle of Hashing . To understand Hashing , we should understand the three terms first i.e Hash Function , Hash Value and Bucket . What is Hash Function , Hash Value and Bucket ? hashCode() function which returns an integer value is the Hash function. The important point...
read more
HashMap works on the principle of Hashing . To understand Hashing , we should understand the three terms first i.e Hash Function , Hash Value and Bucket . What is Hash Function , Hash Value and Bucket ? hashCode() function which returns an integer value is the Hash function. The important point to note that , this method is present in Object class (... more» read less
Comments

HashMap is based on storing key and value pairs, so first lets try and understand the hashcode function right, hashcode function in the object class returns an integer value, so lets say we have an employee class and we want to use the object of this class as a key in the map, so now when we try...
read more
HashMap is based on storing key and value pairs, so first lets try and understand the hashcode function right, hashcode function in the object class returns an integer value, so lets say we have an employee class and we want to use the object of this class as a key in the map, so now when we try and store this object,the map.put api will call the hashcode of the employee class and if not overridden it will use the default implementation from object class which is not advisable at all, so now we have a problem statement of implementing a hashcode method.A simple way to implement hashcode method is call the hashcode of all(all even boolean) the attributes in the Employee class,sum it up and use this integer,this will ensure our hashcodes are diffrent for every object (because only equal objects will have equal hashcode but vice versa may not be true)and actually use the state of the object to calculate the hashcode and inturn when the hashmap put method calls hashcode for employee objects it will work seamlessly without any problems and we want to write when we call the put function. So the map.put function will then use this hashcode to identify if this hashcode exists or not if it does then it returns the earlier object associated is removed and yes the return type of put method if you look up is Object and if there is not object associated to the hashcode then the hashcode and the object are linked in the map. The Get method uses the hashcode method of the key object, again the implementation of the hashcode is important here The remove method works in a similar way using the hashcode to check. The removeAll method simply removes all the associations. Hence all the operations revolve around the hashcode and understanding its implementation is the key to all this. For more read Effective Java by Joshua Blosch. read less
Comments

Computer Professional

It contains only unique elements and maintain one null key.
Comments

Tutor

Hashmap will work based on hashing technique,HashMap in Java works on hashing principle. It is a data structure which allows us to store object and retrieve it in constant time O(1) provided we know the key. In hashing, hash functions are used to link key and value in HashMap. Objects are stored by calling...
read more
Hashmap will work based on hashing technique,HashMap in Java works on hashing principle. It is a data structure which allows us to store object and retrieve it in constant time O(1) provided we know the key. In hashing, hash functions are used to link key and value in HashMap. Objects are stored by calling put(key, value) method of HashMap and retrieved by calling get(key) method. When we call put method, hashcode() method of key object is called so that hash function of map can find a bucket location to store value object, which is actually index of internal array, known as table. HashMap internally store mapping in form of Map. read less
Comments

IT Professional Trainer with 15 years of experience in IT Industry

Hash table based implementation of the Map interface. This implementation provides all of the optional map operations, and permits null values and the null key. (The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls.) This class makes no guarantees as...
read more
Hash table based implementation of the Map interface. This implementation provides all of the optional map operations, and permits null values and the null key. (The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls.) This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time. This implementation provides constant-time performance for the basic operations (get and put), assuming the hash function disperses the elements properly among the buckets. Iteration over collection views requires time proportional to the "capacity" of the HashMap instance (the number of buckets) plus its size (the number of key-value mappings). Thus, it's very important not to set the initial capacity too high (or the load factor too low) if iteration performance is important. An instance of HashMap has two parameters that affect its performance: initial capacity and load factor. The capacity is the number of buckets in the hash table, and the initial capacity is simply the capacity at the time the hash table is created. The load factor is a measure of how full the hash table is allowed to get before its capacity is automatically increased. When the number of entries in the hash table exceeds the product of the load factor and the current capacity, the hash table is rehashed (that is, internal data structures are rebuilt) so that the hash table has approximately twice the number of buckets. read less
Comments

Java Trainer

Note : HashMap and LinkedHashMap stores the elements according to Hashtable algorithm only. In Map interface, elements will be stored using keys. Keys are always unique(duplicates not allowed). Keys are also objects. Duplicate elements are allowed with unique keys. "null" key is...
read more
Note : HashMap and LinkedHashMap stores the elements according to Hashtable algorithm only. In Map interface, elements will be stored using keys. Keys are always unique(duplicates not allowed). Keys are also objects. Duplicate elements are allowed with unique keys. "null" key is allowed in HashMap and LinkedHashMap. "null" object is also allowed. It is allowed to store the elements with heterogenous keys(but unique). Duplicates will be replaced but not rejected. HashMap : 1) available in util package 2) since from jdk 1.2 3) not ordered 4) duplicates allowed with unique keys 5) default capacity is 16 6) default load factor is 0.75 7) HashMap is not synchronized by default. but can be synchronized explicitly as follows. Collections.synchronizedMap(new HashMap(...)); read less
Comments

Expert Java Spring Developer

HashMap works on the principle of Hashing (basically hashing with linear chaining for collision resolution.)
Comments

Java Trainer

TreeMap : 1) TreeMap maintains ascending order of keys. 2) TreeMap does it through Balanced binary trees. 3) null key is not allowed 4) only unique data type keys(homogenous) are allowed. 5) Using what type of key, we are storing the first element into map Object, remaining elements also...
read more
TreeMap : 1) TreeMap maintains ascending order of keys. 2) TreeMap does it through Balanced binary trees. 3) null key is not allowed 4) only unique data type keys(homogenous) are allowed. 5) Using what type of key, we are storing the first element into map Object, remaining elements also must be inserted with the same type of Key. read less
Comments

View 13 more Answers

Related Questions

Is it really needed to do Java training before graduation, to get a job?
Yes, It's must to get better opportunities and to standard alone in IT field. Not only core Java but also learn Spring,Hinernat ,Struts. ANGULARJS add an advantage to get job easily.
Udaybhan

 I want to learn from beginning, please tell me what is the best source to learn (core java)

hi sunaini It is very good that you want to learn programming... I would recommend you c,c++,java and dotnet courses...for becoming a good provrammer.. we provide online training..at lowest prices if...
Sunaini
Which is a good Java training and placement institute for a fresher in Bangalore?
I know an institute in HYderabad which is giving 100% job guarantee or 100% fee refund. They have office in bangalore also, not sure whether they are offering this program in Bangalore. Please visit their...
Raja
0 0
5

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Implementation: What Is JPA And JPA?
The basic Java framework to access the database is JDBC. Unfortunately, with JDBC, a lot of hand work is needed to convert a database query result into Java classes. JPA allows us to work with Java classes...

Advance Java
1) Servlet • Basics of Servlet • Servlet Request • Servlet Collaboration • Servlet Config • Servlet Context • Attribute • Session Tracking • Event and Listener •...
A

Overloading in JAVA
When a class contains more than one method with the same method name but different argument types, then it is called Overloading. Methods are said to be Overloaded methods. Also, know as Compile time...

What is a Programming Language
What is a Language? Language is a communication system of human. What is a programming Language? A programming Language is a formal constructed language design to communicate...

SWITCH STATEMENT IN JAVA
switch statement - condition statement - only once the checking takes place so we recommend use break statement. switch(condition/variable/choice){case 1: //statements break;case 2: // statements break;case...

Recommended Articles

Before we start on the importance of learning JavaScript, let’s start with a short introduction on the topic. JavaScript is the most popular programming language in the world, precisely it is the language - for Computers, the Web, Servers, Smart Phone, Laptops, Mobiles, Tablets and more. And if you are a beginner or planning...

Read full article >

In the domain of Information Technology, there is always a lot to learn and implement. However, some technologies have a relatively higher demand than the rest of the others. So here are some popular IT courses for the present and upcoming future: Cloud Computing Cloud Computing is a computing technique which is used...

Read full article >

Java is the most famous programming language till date. 20 years is a big time for any programming language to survive and gain strength. Java has been proved to be one of the most reliable programming languages for networked computers. source:techcentral.com Java was developed to pertain over the Internet. Over...

Read full article >

Java is the most commonly used popular programming language for the creation of web applications and platform today. Integrated Cloud Applications and Platform Services Oracle says, “Java developers worldwide has over 9 million and runs approximately 3 billion mobile phones”.  Right from its first implication as java 1.0...

Read full article >

Looking for Java Training Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for Java Training Classes?

The best tutors for Java Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Java Training with the Best Tutors

The best Tutors for Java Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more