Skip to content

Instantly share code, notes, and snippets.

@tillson
Last active February 27, 2019 04:22
Show Gist options
  • Save tillson/e8f4b28da005da5622d645dcb2a0cef4 to your computer and use it in GitHub Desktop.
Save tillson/e8f4b28da005da5622d645dcb2a0cef4 to your computer and use it in GitHub Desktop.
Print a HashMap that uses external chaining
public void printString() {
int i = 0;
while (i < table.length) {
MapEntry<K, V> entry = table[i];
System.out.print(i + ": ");
while (entry != null) {
System.out.print(entry.getKey() + " -> ");
entry = entry.getNext();
}
System.out.println("");
i++;
}
System.out.println("Size: " + size);
System.out.println("Load factor: " + (size * 1.0 / table.length));
System.out.println("Keyset: " + keySet().toString());
System.out.println("Values: " + values().toString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment