<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: What is the need to Override Hashcode() and equals() method	</title>
	<atom:link href="https://www.jitendrazaa.com/blog/java/what-is-the-need-to-override-hashcode-and-equals-method/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.jitendrazaa.com/blog/java/what-is-the-need-to-override-hashcode-and-equals-method/</link>
	<description>AI, Salesforce, ServiceNow &#38; Enterprise Tech Guides</description>
	<lastBuildDate>Thu, 11 Jun 2020 11:06:52 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>
		By: Priya		</title>
		<link>https://www.jitendrazaa.com/blog/java/what-is-the-need-to-override-hashcode-and-equals-method/#comment-6148</link>

		<dc:creator><![CDATA[Priya]]></dc:creator>
		<pubDate>Thu, 11 Jun 2020 11:06:52 +0000</pubDate>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=1943#comment-6148</guid>

					<description><![CDATA[Can anyone please explain how the search operation becomes easier because of this hash code in java?
Thanks in advance.]]></description>
			<content:encoded><![CDATA[<p>Can anyone please explain how the search operation becomes easier because of this hash code in java?<br />
Thanks in advance.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Dheeresh Singh		</title>
		<link>https://www.jitendrazaa.com/blog/java/what-is-the-need-to-override-hashcode-and-equals-method/#comment-4978</link>

		<dc:creator><![CDATA[Dheeresh Singh]]></dc:creator>
		<pubDate>Tue, 08 Jan 2019 16:43:31 +0000</pubDate>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=1943#comment-4978</guid>

					<description><![CDATA[Jitendra Zaa is absolutly correct, although the m4 object not been added in the map, but m4 is the exact copy of m2 and m2 is getting used here as a KEY, so it will return m2 object value.
Please correct me if i am wrong.]]></description>
			<content:encoded><![CDATA[<p>Jitendra Zaa is absolutly correct, although the m4 object not been added in the map, but m4 is the exact copy of m2 and m2 is getting used here as a KEY, so it will return m2 object value.<br />
Please correct me if i am wrong.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Dheeresh Singh		</title>
		<link>https://www.jitendrazaa.com/blog/java/what-is-the-need-to-override-hashcode-and-equals-method/#comment-4977</link>

		<dc:creator><![CDATA[Dheeresh Singh]]></dc:creator>
		<pubDate>Tue, 08 Jan 2019 16:39:48 +0000</pubDate>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=1943#comment-4977</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.jitendrazaa.com/blog/java/what-is-the-need-to-override-hashcode-and-equals-method/#comment-852&quot;&gt;Anonymous&lt;/a&gt;.

Pjoshi : Jitendra Zaa is absolutly correct, although the m4 object not been added in the map, but m4 is the exact copy of m2 and m2 is getting used here as a KEY, so it will return m2 object value.
Please correct me if i am wrong.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.jitendrazaa.com/blog/java/what-is-the-need-to-override-hashcode-and-equals-method/#comment-852">Anonymous</a>.</p>
<p>Pjoshi : Jitendra Zaa is absolutly correct, although the m4 object not been added in the map, but m4 is the exact copy of m2 and m2 is getting used here as a KEY, so it will return m2 object value.<br />
Please correct me if i am wrong.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jenny		</title>
		<link>https://www.jitendrazaa.com/blog/java/what-is-the-need-to-override-hashcode-and-equals-method/#comment-4013</link>

		<dc:creator><![CDATA[Jenny]]></dc:creator>
		<pubDate>Thu, 22 Feb 2018 03:38:39 +0000</pubDate>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=1943#comment-4013</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.jitendrazaa.com/blog/java/what-is-the-need-to-override-hashcode-and-equals-method/#comment-3720&quot;&gt;bheemrav mahoviya&lt;/a&gt;.

So true. m4 is not added to map]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.jitendrazaa.com/blog/java/what-is-the-need-to-override-hashcode-and-equals-method/#comment-3720">bheemrav mahoviya</a>.</p>
<p>So true. m4 is not added to map</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Manoj Chiruvolu		</title>
		<link>https://www.jitendrazaa.com/blog/java/what-is-the-need-to-override-hashcode-and-equals-method/#comment-3912</link>

		<dc:creator><![CDATA[Manoj Chiruvolu]]></dc:creator>
		<pubDate>Tue, 09 Jan 2018 12:23:00 +0000</pubDate>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=1943#comment-3912</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.jitendrazaa.com/blog/java/what-is-the-need-to-override-hashcode-and-equals-method/#comment-2231&quot;&gt;Sandip Mangale&lt;/a&gt;.

In Object class .equals() method is used for reference comparison. In String class and all Wrapper classes, .equals() method is overridden for content comparison. in this example program m1 and m2 are two movie objects with different references though we are setting same values. if we don&#039;t override .equals() method, then HashMap is comparing their references and treating them as unique keys.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.jitendrazaa.com/blog/java/what-is-the-need-to-override-hashcode-and-equals-method/#comment-2231">Sandip Mangale</a>.</p>
<p>In Object class .equals() method is used for reference comparison. In String class and all Wrapper classes, .equals() method is overridden for content comparison. in this example program m1 and m2 are two movie objects with different references though we are setting same values. if we don&#8217;t override .equals() method, then HashMap is comparing their references and treating them as unique keys.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Harish Kumara		</title>
		<link>https://www.jitendrazaa.com/blog/java/what-is-the-need-to-override-hashcode-and-equals-method/#comment-3808</link>

		<dc:creator><![CDATA[Harish Kumara]]></dc:creator>
		<pubDate>Mon, 18 Sep 2017 07:17:00 +0000</pubDate>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=1943#comment-3808</guid>

					<description><![CDATA[This is the first reason should be explained everywhere for the question &quot;why hascode() is needed?&quot;. But everybody starts explaining how its being used in hashtables and hashmaps. Thanks Jitendra for this blog.]]></description>
			<content:encoded><![CDATA[<p>This is the first reason should be explained everywhere for the question &#8220;why hascode() is needed?&#8221;. But everybody starts explaining how its being used in hashtables and hashmaps. Thanks Jitendra for this blog.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Override Equals and HashCode in Java Class &#8211; Interview Questions		</title>
		<link>https://www.jitendrazaa.com/blog/java/what-is-the-need-to-override-hashcode-and-equals-method/#comment-3326</link>

		<dc:creator><![CDATA[Override Equals and HashCode in Java Class &#8211; Interview Questions]]></dc:creator>
		<pubDate>Fri, 01 Sep 2017 15:02:52 +0000</pubDate>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=1943#comment-3326</guid>

					<description><![CDATA[[&#8230;] http://www.javaranch.com/journal/2002/10/equalhash.html https://www.jitendrazaa.com/blog/java/what-is-the-need-to-override-hashcode-and-equals-method/ [&#8230;]]]></description>
			<content:encoded><![CDATA[<p>[&#8230;] <a href="http://www.javaranch.com/journal/2002/10/equalhash.html" rel="nofollow ugc">http://www.javaranch.com/journal/2002/10/equalhash.html</a> <a href="https://www.jitendrazaa.com/blog/java/what-is-the-need-to-override-hashcode-and-equals-method/" rel="ugc">https://www.jitendrazaa.com/blog/java/what-is-the-need-to-override-hashcode-and-equals-method/</a> [&#8230;]</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Arun G		</title>
		<link>https://www.jitendrazaa.com/blog/java/what-is-the-need-to-override-hashcode-and-equals-method/#comment-3747</link>

		<dc:creator><![CDATA[Arun G]]></dc:creator>
		<pubDate>Mon, 17 Jul 2017 07:13:00 +0000</pubDate>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=1943#comment-3747</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.jitendrazaa.com/blog/java/what-is-the-need-to-override-hashcode-and-equals-method/#comment-3720&quot;&gt;bheemrav mahoviya&lt;/a&gt;.

You must note that object m2,m3 and m4 will have same hashcode (as implemented in example).
so when you are doing  map.get(m4)  internally it gets hashcode and based on hashcode it will get index of bucket .
and once he will have bucket based on .equals method it will fetch the value &quot;Duplicate Tasvir&quot; .

Hope you will get it.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.jitendrazaa.com/blog/java/what-is-the-need-to-override-hashcode-and-equals-method/#comment-3720">bheemrav mahoviya</a>.</p>
<p>You must note that object m2,m3 and m4 will have same hashcode (as implemented in example).<br />
so when you are doing  map.get(m4)  internally it gets hashcode and based on hashcode it will get index of bucket .<br />
and once he will have bucket based on .equals method it will fetch the value &#8220;Duplicate Tasvir&#8221; .</p>
<p>Hope you will get it.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jitendra Zaa		</title>
		<link>https://www.jitendrazaa.com/blog/java/what-is-the-need-to-override-hashcode-and-equals-method/#comment-3721</link>

		<dc:creator><![CDATA[Jitendra Zaa]]></dc:creator>
		<pubDate>Sun, 18 Jun 2017 16:47:00 +0000</pubDate>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=1943#comment-3721</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.jitendrazaa.com/blog/java/what-is-the-need-to-override-hashcode-and-equals-method/#comment-3720&quot;&gt;bheemrav mahoviya&lt;/a&gt;.

line 50-68, all objects are inserted in map. Now to get value, we just need to create an object and that will act as key, so need to insert in map again.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.jitendrazaa.com/blog/java/what-is-the-need-to-override-hashcode-and-equals-method/#comment-3720">bheemrav mahoviya</a>.</p>
<p>line 50-68, all objects are inserted in map. Now to get value, we just need to create an object and that will act as key, so need to insert in map again.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: bheemrav mahoviya		</title>
		<link>https://www.jitendrazaa.com/blog/java/what-is-the-need-to-override-hashcode-and-equals-method/#comment-3720</link>

		<dc:creator><![CDATA[bheemrav mahoviya]]></dc:creator>
		<pubDate>Sun, 18 Jun 2017 12:53:00 +0000</pubDate>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=1943#comment-3720</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.jitendrazaa.com/blog/java/what-is-the-need-to-override-hashcode-and-equals-method/#comment-841&quot;&gt;Shailendra kumar&lt;/a&gt;.

Sorry but Can i know if you are not putting m4 object in map, How you are able to retrieve it.

for (Movie mm : map.keySet()) {

System.out.println(map.get(mm).toString());

 }

 Movie m4 = new Movie();

m4.setActor(&quot;Akshay&quot;);

 m4.setName(&quot;Taskvir&quot;);

 m4.setReleaseYr(2010);

 if (map.get(m4) == null) {

 System.out.println(&quot;----------------&quot;);

 System.out.println(&quot;Object not found&quot;);

 System.out.println(&quot;----------------&quot;);
 } else {

 System.out.println(&quot;----------------&quot;);

 System.out.println(map.get(m4).toString());

 System.out.println(&quot;----------------&quot;);

 }

 }

Output:

Khiladi

Duplicate Tasvir

ThankYou

—————-

Duplicate Tasvir  // M4 object 

—————-]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.jitendrazaa.com/blog/java/what-is-the-need-to-override-hashcode-and-equals-method/#comment-841">Shailendra kumar</a>.</p>
<p>Sorry but Can i know if you are not putting m4 object in map, How you are able to retrieve it.</p>
<p>for (Movie mm : map.keySet()) {</p>
<p>System.out.println(map.get(mm).toString());</p>
<p> }</p>
<p> Movie m4 = new Movie();</p>
<p>m4.setActor(&#8220;Akshay&#8221;);</p>
<p> m4.setName(&#8220;Taskvir&#8221;);</p>
<p> m4.setReleaseYr(2010);</p>
<p> if (map.get(m4) == null) {</p>
<p> System.out.println(&#8220;&#8212;&#8212;&#8212;&#8212;&#8212;-&#8220;);</p>
<p> System.out.println(&#8220;Object not found&#8221;);</p>
<p> System.out.println(&#8220;&#8212;&#8212;&#8212;&#8212;&#8212;-&#8220;);<br />
 } else {</p>
<p> System.out.println(&#8220;&#8212;&#8212;&#8212;&#8212;&#8212;-&#8220;);</p>
<p> System.out.println(map.get(m4).toString());</p>
<p> System.out.println(&#8220;&#8212;&#8212;&#8212;&#8212;&#8212;-&#8220;);</p>
<p> }</p>
<p> }</p>
<p>Output:</p>
<p>Khiladi</p>
<p>Duplicate Tasvir</p>
<p>ThankYou</p>
<p>—————-</p>
<p>Duplicate Tasvir  // M4 object </p>
<p>—————-</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Minified using Disk

Served from: www.jitendrazaa.com @ 2026-09-17 18:09:15 by W3 Total Cache
-->