Created
March 23, 2015 02:44
-
-
Save tauty/bfa30f53eb135e21f226 to your computer and use it in GitHub Desktop.
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
package tetz42.util; | |
import static tetz42.util.ObjDumper4j.*; | |
import java.util.HashMap; | |
public class Investigation_HashMapBehaviour { | |
/** | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
new Investigation_HashMapBehaviour().exe(); | |
} | |
HashMap<String, Object> hm = new HashMap<>(); | |
// HashMap<String, Object> hm = applicableMap(100); | |
private void exe() { | |
for (int i = 0; i < 100; i++) { | |
System.out.println("-------------------[" + i + "]---------------------"); | |
hm.put(String.valueOf(i), i); | |
System.out.println(inspect(hm)); | |
} | |
} | |
public static <K, V> HashMap<K, V> applicableMap(int numberToStore) { | |
return applicableMap(numberToStore, (float) 1); | |
} | |
public static <K, V> HashMap<K, V> applicableMap(int numberToStore, float loadFactor) { | |
int applicableNumber = (int) (numberToStore / loadFactor) + 1; | |
return new HashMap<K, V>(applicableNumber, loadFactor); | |
} | |
} | |
/* Like below text will be shown when you perform this program. | |
-------------------[10]--------------------- | |
HashMap@7f5{ | |
table = Entry[]@39813c12[ | |
Entry@30{ | |
key = "3" | |
value = 3 | |
next = null | |
hash = 48 | |
} | |
Entry@30{ | |
key = "2" | |
value = 2 | |
next = null | |
hash = 49 | |
} | |
Entry@615{ | |
key = "10" | |
value = 10 | |
next = Entry@30{ | |
key = "1" | |
value = 1 | |
next = null | |
hash = 50 | |
} | |
hash = 1650 | |
} | |
Entry@30{ | |
key = "0" | |
value = 0 | |
next = null | |
hash = 51 | |
} | |
Entry@30{ | |
key = "7" | |
value = 7 | |
next = null | |
hash = 52 | |
} | |
Entry@30{ | |
key = "6" | |
value = 6 | |
next = null | |
hash = 53 | |
} | |
Entry@30{ | |
key = "5" | |
value = 5 | |
next = null | |
hash = 54 | |
} | |
Entry@30{ | |
key = "4" | |
value = 4 | |
next = null | |
hash = 55 | |
} | |
null | |
null | |
Entry@30{ | |
key = "9" | |
value = 9 | |
next = null | |
hash = 58 | |
} | |
Entry@30{ | |
key = "8" | |
value = 8 | |
next = null | |
hash = 59 | |
} | |
null | |
null | |
null | |
null | |
] | |
size = 11 | |
threshold = 12 | |
loadFactor = 0.75 | |
modCount = 11 | |
useAltHashing = false | |
hashSeed = -1758889794 | |
entrySet = EntrySet@7f5[ | |
Entry@30{...} | |
Entry@30{...} | |
Entry@615{...} | |
Entry@30{...} | |
Entry@30{...} | |
Entry@30{...} | |
Entry@30{...} | |
Entry@30{...} | |
Entry@30{...} | |
Entry@30{...} | |
Entry@30{...} | |
] | |
[java.util.AbstractMap] | |
keySet = null | |
values = null | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment