bujjulu Posted November 14, 2013 Report Posted November 14, 2013 public class ObjectComparator { public static void main(String []args) { Integer a = new Integer(5); Integer b = new Integer(5); System.out.println(a.equals(b)); String abc="venu"; String bcd="venu"; String a1= new String("venu1"); System.out.println(abc.equals(bcd)); System.out.println(abc.equals(a1)); } } out put true true false Read theory below Object class provides two methods hashcode() and equals() to represent the identity of an object. It is a common convention that if one method is overridden then other should also be implemented. Before explaining why, let see what the contract these two methods hold. As per the Java API documentation: 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 execution of the same application. If two objects are equal according to the equals(object) method, then calling the hashCode() method on each of the two objects must produce the same integer result. It is NOT required that if two objects are unequal according to the equals(Java.lang.Object) method, then calling the hashCode() method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hashtables. I have written how the hashcode values will be popluated in this URL http://iforerunner.com/sunjava/posts/list/0/3156.page#16815
Ladies_Tailor Posted November 14, 2013 Report Posted November 14, 2013 java ante jailor mama vachestadu
sigsegv Posted November 14, 2013 Report Posted November 14, 2013 "such a horrible langugage " -- linus
bujjulu Posted November 14, 2013 Author Report Posted November 14, 2013 "such a horrible langugage " -- linus :3D_Smiles:
cherlapalli_jailer Posted November 14, 2013 Report Posted November 14, 2013 java ante jailor mama vachestadu edo manaki koodu gudda anni java ne kada mari @3$%
cherlapalli_jailer Posted November 14, 2013 Report Posted November 14, 2013 how equalsignorecase works? both will be converted to one form? will that take extra time / memory ??
innovative Posted November 14, 2013 Report Posted November 14, 2013 how equalsignorecase works? both will be converted to one form? will that take extra time / memory ?? equals and equalsignorecase rendu okela work chesthay implementation perspective theskunte.. jus that equalsignorecase ingnores string case equalsignorecase extra time/memory em theskodhu because in both the cases, method goes and check String references not actual Strings. 1) First string references check chesthadhi 2) then strings length 3) then string characters then it will confirm whether both the strings are equal or not ani .. so two methods same amount of time/memory theskuntay .. hope u r clear ...
dotnetrockz Posted November 14, 2013 Report Posted November 14, 2013 Java and .net oke talli ki puttinna kavala pillalu.....
innovative Posted November 14, 2013 Report Posted November 14, 2013 Java and .net oke talli ki puttinna kavala pillalu..... agreed .. Just like littlemoon and me :D
k2s Posted November 14, 2013 Report Posted November 14, 2013 public class ObjectComparator { public static void main(String []args) { Integer a = new Integer(5); Integer b = new Integer(5); System.out.println(a.equals(b)); String abc="venu"; String bcd="venu"; String a1= new String("venu1"); System.out.println(abc.equals(bcd)); System.out.println(abc.equals(a1)); } } out put true true false Read theory below Object class provides two methods hashcode() and equals() to represent the identity of an object. It is a common convention that if one method is overridden then other should also be implemented. Before explaining why, let see what the contract these two methods hold. As per the Java API documentation: 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 execution of the same application. If two objects are equal according to the equals(object) method, then calling the hashCode() method on each of the two objects must produce the same integer result. It is NOT required that if two objects are unequal according to the equals(Java.lang.Object) method, then calling the hashCode() method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hashtables. I have written how the hashcode values will be popluated in this URL http://iforerunner.com/sunjava/posts/list/0/3156.page#16815
Spartan Posted November 14, 2013 Report Posted November 14, 2013 agreed .. Just like littlemoon and me :D
dotnetrockz Posted November 14, 2013 Report Posted November 14, 2013 agreed .. Just like littlemoon and me :D good good...db lo classmates,friends...friends friends undadadam chusam kaani...ila oke family members undadam first of its kind anukunta....
Recommended Posts