0 votes
in JAVA by
What is default size of ArrayList and HashMap in Java?

1 Answer

0 votes
by

As of Java 7 now, default size of ArrayList is 10 and default capacity of HashMap is 16, it must be power of 2. Here is code snippet from ArrayList  and HashMap class :

// from ArrayList.java JDK 1.7

private static final int DEFAULT_CAPACITY = 10;  

//from HashMap.java JDK 7

static final int DEFAULT_INITIAL_CAPACITY = 1 << 4; // aka 16

Related questions

0 votes
asked Oct 23, 2020 in JAVA by rahuljain1
0 votes
asked Oct 19, 2020 in JAVA by rahuljain1
...