Menu
Menu
DaniWeb
Log In
Sign Up
Read
Contribute
Meet
Search
Search
About 427 results for
hashcode
- Page 1
Re: hashCode help
Programming
Software Development
15 Years Ago
by BestJewSinceJC
…Test is probably failing is because calling str.
hashCode
calls the
hashCode
method of the String class, it does …in your String. For example, [CODE] public static int
hashCode
(String str){ String str2 = str.substring(str.length() - … If you don't understand how to implement the
hashCode
method, then perhaps you should read about [URL="…
Re: hashCode help
Programming
Software Development
15 Years Ago
by Alpdog14
…on the string [i]first[/i] and call
hashcode
on the returned substring. Edit: BTW "… test for this. I currently have: [CODE]@Test //
hashCode
() public void testHashCode1() { String str = "hello&…String str2 = "jello"; assertEquals(str.
hashCode
(), str2.
hashCode
()); }[/CODE] but the output is failing and giving…
hashCode help
Programming
Software Development
15 Years Ago
by Alpdog14
…Here is my current code: [CODE]public int
hashCode
(String value){ String test = value; int hash…}[/CODE] Here is my Junit Test: [CODE] @Test //
hashCode
() public void testHashCode1() { //Integer key1 = 123; String key2 …quot;and"; assertEquals("and", key2.
hashCode
()); }[/CODE] Everytime I run my test it …
Re: hashCode help
Programming
Software Development
15 Years Ago
by masijade
Use substring on the string [i]first[/i] and call
hashcode
on the returned substring. Edit: BTW "as part of … tell us the [i]why[/i] you only want the
hashcode
of the last few chars (or the last few digits… of the
hashcode
, you don't seem to be too clear on [i…
Re: hashCode help
Programming
Software Development
15 Years Ago
by jwenting
trying to put business logic into your
hashcode
algorithm (which you're attempting to do) is almost …always a bad idea. The
hashcode
should be such that items can be quickly identified in…items returning true on calling equals() also returning the same
hashcode
, but that should be a natural consequence of the above…
Re: hashCode help
Programming
Software Development
15 Years Ago
by Alpdog14
… though, here is my Revised code: [CODE]public static int
hashCode
(String str){ int zInt; //str = str.toString(); if(str.length… = "jello"; assertEquals("lo", key1.
hashCode
()); assertEquals("lo", key2.
hashCode
()); } }[/CODE] Trying to pull in the String…
Re: hashCode help
Programming
Software Development
15 Years Ago
by Alpdog14
… entire thing?[/QUOTE] Well I am trying to return the
hashCode
of the last two or three digits because its part… take in parameters but how to I use the original
hashCode
() method that takes no parameters, here is my working code…
Re: hashCode help
Programming
Software Development
15 Years Ago
by Alpdog14
[QUOTE=BestJewSinceJC;1138775]Well, can you post your current
hashCode
method so we can look at it and see why … be?[/QUOTE] Well my current code is: [CODE]public int
hashCode
(){ int hash = MyMap.key; String str = Integer.toString(MyMap.key…
Re: hashCode help
Programming
Software Development
15 Years Ago
by BestJewSinceJC
Your
hashCode
method returns an int. How could a String (which is … to tackle concepts such as hash tables (and by connection,
hashCode
). If you spend some serious time delving into some beginner…
Re: hashCode help
Programming
Software Development
15 Years Ago
by masijade
Well, certainly [i]not[/i] with * and + You're looking for substring if you [i]really[/i] want to do that, but I don't see any poinf to it, especially since
hashcode
is suppossed to return an int and not a String, so returning the "last 2 or 3 chars" isn't even applicable.
Re: hashCode help
Programming
Software Development
15 Years Ago
by Alpdog14
… little but its still not returning, [CODE]@Override public int
hashCode
() { int hash = 1; Cell<K,V> cell = int…
Re: hashCode help
Programming
Software Development
15 Years Ago
by masijade
Like I said, use substring on the strings and call
hashcode
on that substring.
Re: hashCode help
Programming
Software Development
15 Years Ago
by BestJewSinceJC
Well, can you post your current
hashCode
method so we can look at it and see why that might be?
Re: hashCode help
Programming
Software Development
15 Years Ago
by BestJewSinceJC
[CODE] int number = 2567; String num = Integer.toString(number); String str = num.substring(//put correct argument here); [/CODE] I'm intentionally omitting the argument to substring so that I'm not just giving you all of the code. Oh, and keep in mind that in order to properly get the substring, you should check the length of the String first and…
Re: hashCode help
Programming
Software Development
15 Years Ago
by masijade
[i]Why[/i] do only want the last two digits? In any case, to return those as an int simply do modulus 100. Do you know what hascode is meant for? Even if you do only return the last two digits they will [i]still[/i] never match the original String. [i]What[/i], exactly, are you trying to acheive? What is your [i]goal[/i] with this entire thing…
String Pool & hashCode wroking?
Programming
Software Development
14 Years Ago
by nitins60
…: "); System.out.println(s1.
hashCode
()+ " "+ s2.
hashCode
()+" "+s3.
hashCode
()); System.out.println("== Check: …understand why s1,s2,s3 are having same
hashcode
although i created as strings and objects as … working is fine. except that
hashcode
. if they are all having same
hashcode
how the == operator checks if …
Re: String Pool & hashCode wroking?
Programming
Software Development
14 Years Ago
by ~s.o.s~
…can't understand why s1,s2,s3 are having same
hashcode
although i created as strings and objects as shown[/…quote] As already mentioned
hashCode
depends on the value of the object. Plus, when …equals() you need to provide a logical implementation of the
hashCode
() method which [URL="http://www.xyzws.com/javafaq/…
equals & hashcode help
Programming
Software Development
14 Years Ago
by Alpdog14
… compares weight and value and I need help developing a
hashcode
and Junit tests to test them, here is my class…(t.weight)); } @Override public int
hashCode
(){ int h1 = new Double (value).
hashCode
(); int h2 = new Double (weight).
hashCode
(); final int HASH_MULTIPLIER = 29; int…
Re: String Pool & hashCode wroking?
Programming
Software Development
14 Years Ago
by masijade
Because the
hashCode
is based on the Strings [i]value[/i] not its reference.
Re: String Pool & hashCode wroking?
Programming
Software Development
14 Years Ago
by masijade
No, the "hash" has [i]nothing[/i] to do with the reference value. The "hash" is [i]calculated[/i] everytime you call the
hashCode
function and the calculation is based upon the Objects [i]value[/i] not its reference.
Re: equals & hashcode help
Programming
Software Development
14 Years Ago
by ~s.o.s~
…) in which case you automatically get a good equals and
hashCode
implementation. Also, when you say 'weight', is it the physical… Eclipse, you can ask Eclipse to generate a equals() and
hashCode
() implementation for you. ALT + SHIFT + S then h…
Re: equals & hashcode help
Programming
Software Development
14 Years Ago
by Alpdog14
…) in which case you automatically get a good equals and
hashCode
implementation. Also, when you say 'weight', is it the physical… Eclipse, you can ask Eclipse to generate a equals() and
hashCode
() implementation for you. ALT + SHIFT + S then h.[/QUOTE] This…
Brute-forcing a String.hashCode() value
Programming
Software Development
13 Years Ago
by Delocaz
…-force the result of something like [ICODE]"Hi".
hashCode
()[/ICODE]. I have no idea where to start. I looked…-force cracker on Google, and modify it to use [ICODE]
hashCode
()[/ICODE]. It went like [ICODE]"a", "b…
Re: Brute-forcing a String.hashCode() value
Programming
Software Development
13 Years Ago
by JamesCherrill
Sorry, but I'm not sufficiently sure that reverse-engineering a
hashcode
isn't for some dubious purpose, so I'm staying out of this. I suspect my colleagues feel the same. Maybe you can explain more about why you are doing this to reassure us that it's 100% legitimate?
Re: Brute-forcing a String.hashCode() value
Programming
Software Development
13 Years Ago
by Delocaz
It's to convert a Minecraft seed (
hashCode
() of string given by user, then used in a random generator as seed)(something like -6007422400597289330) to a textual representation (something like zQV5GH@zN). That makes it (somewhat) easier to remember.
Re: Brute-forcing a String.hashCode() value
Programming
Software Development
13 Years Ago
by Delocaz
Umm, the goal for this is like an MD5 brute-force cracker, but with String.
hashCode
():
Re: String Pool & hashCode wroking?
Programming
Software Development
14 Years Ago
by nitins60
then is there any way to print any values based on reference or creation of objects?
Re: String Pool & hashCode wroking?
Programming
Software Development
14 Years Ago
by masijade
What are you trying to accomplish? Edit: And no, you cannot print out the reference value (in the normal scheme of things), but trust me, the JVM has access to it.
Re: String Pool & hashCode wroking?
Programming
Software Development
14 Years Ago
by nitins60
I believe its bit different in C#. in c#, whenever i create an object, that will return new hash value. but in Java, string pool is holding same hash for variable or object which reference to it.
Re: equals & hashcode help
Programming
Software Development
14 Years Ago
by thekashyap
[QUOTE=Alpdog14;1511940]Can anyone guide me on how to create the tests for this?[/QUOTE] In eclipse, right click on the .java file and say New->JUnit Testcase.. :) Select the methods you want to test, then implement the methods.
1
2
3
8
Next
Last
Search
Search
Forums
Forum Index
Hardware/Software
Recommended Topics
Programming
Recommended Topics
Digital Media
Recommended Topics
Community Center
Recommended Topics
Latest Content
Newest Topics
Latest Topics
Latest Posts
Latest Comments
Top Tags
Topics Feed
Social
Top Members
Meet People
Community Functions
DaniWeb Premium
Newsletter Archive
Markdown Syntax
Community Rules
Developer APIs
Connect API
Forum API Docs
Tools
SEO Backlink Checker
Legal
Terms of Service
Privacy Policy
FAQ
About Us
Advertise
Contact Us
© 2025 DaniWeb® LLC