0

ハッシュマップの現在の負荷率と容量を見つける方法は?

Map m = new HashMap(10,1);

//but after lots of works

Here how to get current values.
4

2 に答える 2

2

負荷率と容量を取得できるはずはありません。これらは 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);
于 2013-11-14T03:42:28.393 に答える