difference between equals() and hashCode()

前端 未结 7 791
心在旅途
心在旅途 2021-02-05 13:29

I want a brief definition about the equals() , \"==\" and hashCode(). If i run following code means the output will be \"true false 2420395 2420395\". But i had understand that

7条回答
  •  感动是毒
    2021-02-05 14:16

    equals() only compare string it's does not check reference of string

    but '==' check reference and data both

    in 1st case String str = "Name"; only one object is created but in

    2nd case Two object is created

    String str1 = new String("Name");
    

    then reference are not same of both string that means it returns false

提交回复
热议问题