Default Object.toString() in hashcode

0 votes

Can someone explain why do we get hashcode in the output of System.out.println(someObj.toString())?

Such as:

someObjectClassname@hashcodenumber

Oct 30, 2018 in Java by 93.lynn
• 1,600 points
56 views

1 answer to this question.

0 votes

Well, the hash code object is the only standard identifier provided by Java that helps in differentiating between various arbitrary objects. Let me add here that it's not unique, but as we know that the equal objects contain/ returns the same hash code. Thus here, when the default toString() method is used it gives the object class and its hash code to help you differentiate between the objects. 

For more, you can refer here: hashCode() method 

answered Oct 30, 2018 by code.reaper12
• 3,470 points

Related Questions In Java

0 votes
2 answers

One line initialization of an ArrayList object in Java

In Java 8 or earlier: List<String> string = ...READ MORE

answered Jul 26, 2018 in Java by samarth295
• 2,190 points
426 views
0 votes
2 answers

What is the use of toString method in Java and how can I use it ?

Whenever you require to explore the constructor ...READ MORE

answered Aug 23, 2018 in Java by Daisy
• 8,080 points
1,018 views
+15 votes
18 answers

How can I convert String to JSON object in Java?

Hi @Daisy You can use Google gson  for more ...READ MORE

answered Feb 7, 2019 in Java by Suresh
• 700 points
104,605 views
0 votes
2 answers

Determining Class of an Object in Java

You can use: Object instance = new SomeClass(); instance.getClass().getName(); ...READ MORE

answered Nov 26, 2018 in Java by Sushmita
• 6,880 points
91 views
0 votes
2 answers

what is the best way to convert an ArrayList to a String

You could probably use the Joiner class ...READ MORE

answered Aug 19, 2019 in Java by Sirajul
• 45,590 points
89 views
0 votes
1 answer

Java String interning

The String.intern() method of Java Strings ensures ...READ MORE

answered Oct 25, 2018 in Java by geek.erkami
• 2,660 points
65 views
+5 votes
3 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,400 points

edited Nov 6, 2018 by Omkar 12,883 views
0 votes
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,510 points
2,669 views
0 votes
1 answer

Purpose of “String args[]” in the “psvm” of Java

Let me give you the complete explanation ...READ MORE

answered May 7, 2018 in Java by code.reaper12
• 3,470 points
142 views
0 votes
1 answer

Need for finalize() in Java

finalize() is a method called by the ...READ MORE

answered May 8, 2018 in Java by code.reaper12
• 3,470 points
96 views