如何找到hashmap当前的负载因子和容量?
Map m = new HashMap(10,1);
//but after lots of works
Here how to get current values.
您不应该能够获得负载系数和容量;它们是 hashmap 类的实现细节。但是,您可以使用反射。但尽量避免使用它,这通常是一个坏主意。
Field f1 = m.getClass().getDeclaredField("table");
f1.setAccessible(true);
int capacity = f1.get(m).length;
Field f2 = m.getClass().getDeclaredField("threshold");
f2.setAccessible(true);
int currentLoadFactor = f2.get(m);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)