HashSet
의 초기 용량은 어떻게됩니까?HashSet의 초기 용량은 어떻게 구합니까?
import java.util.*;
import java.lang.reflect.Field;
public class Demo
{
static int getCapacity(ArrayList<?> l) throws Exception
{
Field dataField = ArrayList.class.getDeclaredField("elementData");
dataField.setAccessible(true);
return ((Object[]) dataField.get(l)).length;
}
public static void main(String args[])
{
ArrayList a = new ArrayList();
System.out.println(getCapacity(a));
HashSet h = new HashSet(); //in case HashSet what we do
System.out.println(h.capacity());
}
}
실제로는 HashSet
클래스에는 용량 방법이 없습니다. 그렇다면 용량을 어떻게 얻으시겠습니까 HashSet
? HashSet
개체의 초기 용량을 어떻게 얻을 수 있습니까?
왜? 그것을 알기 위해 어떤 좋은 일을합니까? – EJP