Last active
September 9, 2022 10:22
-
-
Save thecodinganalyst/caa2830f4d6a96f08afb84f85b0d3df2 to your computer and use it in GitHub Desktop.
HashMap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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