tag:blogger.com,1999:blog-8712770457197348465.post3711079374573322698..comments2024-03-29T00:43:22.798-07:00Comments on Javarevisited: 10 Equals and HashCode Interview Questions in Javajavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-8712770457197348465.post-78518262941629888762016-05-05T05:55:52.445-07:002016-05-05T05:55:52.445-07:00In case of null as a key hashcode() is not called ...In case of null as a key hashcode() is not called map put this null key as index[0].as it's very clear that only one null key can be stored in a map. <br />So when you call get(key) it retrieves from index[0] without calling hashcode().<br /><br />Arvind Anonymoushttps://www.blogger.com/profile/02941644805328238325noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-22169484497049074472015-03-25T05:02:24.494-07:002015-03-25T05:02:24.494-07:00@SARAL SAXENA
Did you copy-paste your comments fro...@SARAL SAXENA<br />Did you copy-paste your comments from following ?? LOL !!!<br />http://www.xyzws.com/javafaq/why-always-override-hashcode-if-overriding-equals/20Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-8511965391400377972014-03-24T00:57:04.665-07:002014-03-24T00:57:04.665-07:00@ Javi here in this article we can also add.
...@ Javi here in this article we can also add.<br /><br /><br /> Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another SARAL SAXENAhttps://www.blogger.com/profile/01084233786047386880noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-29548322189845442452014-03-23T22:44:27.581-07:002014-03-23T22:44:27.581-07:00@Javin nice article but I want to add few points i...@Javin nice article but I want to add few points in it that will bring more clearity..<br /><br /><br /><br />It is not always necessary to override hashcode and equals. But if you think you need to override one, then you need to override both of them. Let's analyze what whould happen if we override one but not the other and we attempt to use a Map.<br /><br />Say we have a class like this SARAL SAXENAhttps://www.blogger.com/profile/01084233786047386880noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-17259862963002418172014-01-19T21:05:48.302-08:002014-01-19T21:05:48.302-08:00Here is a tricky question I was asked on Equals, W...Here is a tricky question I was asked on Equals, What is the value of following expression and Why?<br /><br />Integer.valueOf(1).equals(Long.valueOf(1))<br /><br />Answer is false, because even though numeric value is same, they are of different types e.g. Integer and Long because Integer.valueOf(1) will return Integer, while Long.valueOf(1) will return Long, Since equals method of Integer classAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-59258017024525221762013-09-02T03:52:53.129-07:002013-09-02T03:52:53.129-07:00as we know HashMap use hashCode() method to get th...as we know HashMap use hashCode() method to get the hashcode of key i.e. key.hashCode(). I can put null in the key that will be stored in HashMap but null.hashCode() should throw NullPointerException ?<br />Anonymousnoreply@blogger.com