No Dream Too Big
SCJP6 with score 90%. I am conscious of my ignorance and ready to learn from everyone.
Emanuele Ghe wrote:Hi,
the best thing for you is to try the program yourself in spite of making this kind of posts.
You will learn a lot more trying things in spite of asking.
You should ask only when, even trying, you can't understand something, or you need some kind of clarification.
No Dream Too Big
Emanuele Ghe wrote:Hi,
the best thing for you is to try the program yourself in spite of making this kind of posts.
You will learn a lot more trying things in spite of asking.
You should ask only when, even trying, you can't understand something, or you need some kind of clarification.
SCJP 6.0 96%
(Connecting the Dots ....)
SCJP 6.0 96%
(Connecting the Dots ....)
Emanuele Ghe wrote:Hi,
the best thing for you is to try the program yourself in spite of making this kind of posts.
You will learn a lot more trying things in spite of asking.
SCJP 6.0 96%
(Connecting the Dots ....)
Censorship is the younger of two shameful sisters, the older one bears the name inquisition.
-- Johann Nepomuk Nestroy
No Dream Too Big
Peter Taucher wrote:Doesn't the hashCode method of String base on it's content? And I think StringBuilder doesn't provide an implementation of hashCode, so it uses Object's method. Therefore the result should be 'false true'.
No Dream Too Big
SCJP SE 6.0, SCWCD J2EE 5
We cannot say anything about the hashcode values of Different Objects unless they are Strings which overrides equals() method, and if two objects are equal then they must have same hashcode values.
SCJP 6.0 96%
(Connecting the Dots ....)
Edwin Dalorzo wrote:Fist of all, we must set clear that two different objects may have the same hash code.
The definition of hashCode() method in Javadocs clearly states that "as much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects.".
Which basically means two different objects may have the same hashCode. However, the hashCode() and equals() definition in Javadocs guarantees that if equals() returns true, than the hashCode() of the two objects being compared should be the same.
That being said, we know that StringBuilder does not override neither equals() nor hashCode(), but String does. Therefore, we know that the hashCode() for two equal Strings must be the same. Therefore, the second hashCode comparison must always be true.
We cannot tell if the first hashCode comparison will produce true or false, since it is comparing two different objects. The classical implementation of hashCode in object is to return the objects memory address. If by chance this number corresponded with the hashCode generated by String based on its containing characters, then the comparison would yield true, otherwise false.
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
L. Wei wrote:
String a = "abc";
StringBuilder b = new StringBuilder("abc");
a.equals(b); // will cause compile error, they are two types, not comparable.
SCJP 6, OCMJD 6, OCPJWSD 6
I no good English.
Get me the mayor's office! I need to tell her about this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|