Learnitweb

What is the default capacity of collection framework classes in Java?

The answer to this questions is – it depends on the Java version. For example, in Java 8 default capacity of ArrayList is 0 until we add at least one object into the ArrayList object. But to answer this question as of Java 7, we mention following default capacity of collection framework classes in Java:

  • Vector : 10
  • ArrayList: 10
  • LinkedList: Does not have a capacity
  • HashMap: 16
  • ConcurrentHashMap: 16
  • HashSet: 16 (as it’s based on a HashMap)
  • LinkedHashSet: 16
  • TreeSet: Does not have a capacity