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,620 points
173 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,200 points
1,164 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,110 points
1,565 views
+15 votes
22 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
• 720 points
192,877 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,890 points
293 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
• 58,130 points
179 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,680 points
133 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,450 points

edited Nov 6, 2018 by Omkar 31,650 views
+1 vote
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,520 points
4,515 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
245 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
153 views