Skip to content

Instantly share code, notes, and snippets.

@thecodinganalyst
Last active September 9, 2022 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thecodinganalyst/caa2830f4d6a96f08afb84f85b0d3df2 to your computer and use it in GitHub Desktop.
Save thecodinganalyst/caa2830f4d6a96f08afb84f85b0d3df2 to your computer and use it in GitHub Desktop.
HashMap
class HashMapDemo {
public static void main(String[ ] args) {
String key = "superman";
int size = 15;
System.out.println("Key: " + key);
int hashCode = key.hashCode();
System.out.println("HashCode: " + hashCode);
System.out.println("HashCode (Binary): " + Integer.toBinaryString(hashCode));
int h;
int hash = (h = key.hashCode()) ^ (h >>> 16);
System.out.println("Hash: " + hash);
System.out.println("Hash (Binary): " + Integer.toBinaryString(hash));
System.out.println("Size (Binary): " + Integer.toBinaryString(size));
int x = size & hash;
System.out.println("Location: " + x);
System.out.println(Integer.toBinaryString(x));
// Key: superman
// HashCode: -1673281537
// HashCode (Binary): 10011100010000111011111111111111
// Hash: -1673321540
// Hash (Binary): 10011100010000110010001110111100
// Size (Binary): 1111
// Location: 12
// 1100
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment