Object.toString() does not return the hashcode value of the object in java but instead give some string

  • A+
Category:Languages

I have written the following code:-

Test ob = new Test(); System.out.println(ob.toString()); System.out.println(ob.hashCode()); 

and the output is

Test@15db9742 366712642 

i understand that the second value is the hashcode of the object and it is an integer value but i am not able to understand what is the first value. If it is the hashcode of the object then how can it be string and not integer

 


It represents classname@HashCode_in_Hexadeciaml_form. So, the string which you are seeing is actually the hexadecimal form of the integer hashcode

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: