What is the default capacity of ArrayList in JAVA?

  • Question: What is the default capacity of java.util.ArrayList?
  • Answer: It is exactly 10.

Why not any power of 2? Well, Sun engineers believed after long and costly research, that 10 is the best number You can pick. What is more curious, default initial capacity of java.util.HashMapis 16, which makes more sense.

What do You think, something is missing here? Is 10 really a perfect fit for array type collections?

Quick questions and answers on JAVA

Hi Folks 🙂

Sometimes, You have only 5 minutes of Your life to eat, to work out or just to drink a beer. We believe, that 5 mins are enough to read some random (currently only) Java (as we are focusing more on Java) – Q&A „mini-articles”. According to the rule of 5 minutes, we are also (sometimes) veeeeery busy, but at the same time, we are in a strong desire to publish something!

All Java related Q&A entries will be here: JAVA: Questions and Answers

PS: Yes, we are lazy… What can we do? 🙂