What is the default size of Vector, Arraylist, Hashtable, Hashmap, Hashset in Java?

Showing Answers 1 - 0 of 0 Answers

avishek

  • Sep 22nd, 2007
 

As we know vector, ArrayList, etc are all growable so I think the size is not specific but depends upon the heap area of JVM. If I am not right please tell.

  Was this answer useful?  Yes

deepak

  • Nov 24th, 2007
 

Vector has a default size of 10

  Was this answer useful?  Yes

SChilukuri

  • Dec 4th, 2007
 

A vector has its default capacity which is 10 elements, here size is different from capacity, after 10 element if we enter one element the capacity of vector changes to 20 were as size is 11 only, for example if you have entered 21 elements in a vector, then if you print v.size it results 21 but v.capacity it results 30 If you have any further queries pls let me know

  Was this answer useful?  Yes

Ajay

  • Nov 21st, 2011
 

vector size every time get double.

For example: Initially capacity is 10, when when you will put 11 th value in this it will give you size 20, when you will add 21 value its size would be 40 ans after that 80 ans so on,
but in case of array list its increment 50 % of the existing.

  Was this answer useful?  Yes

Ajay

  • Nov 21st, 2011
 

Instead of 30 it would give 40.

  Was this answer useful?  Yes

Dharmendra

  • Aug 9th, 2012
 

ArrayList , Vector default size is 10. vector increment is 10 and array list is 10/2

  Was this answer useful?  Yes

manju

  • Mar 3rd, 2014
 

16

  Was this answer useful?  Yes

Saurabh Ranjan

  • Jan 1st, 2015
 

after 10th element if we insert 11th element in ArrayList it will increase by capacity=(currentCapacity*3/2)+1

  Was this answer useful?  Yes

mitesh

  • Oct 10th, 2015
 

Current Capacity+3/2,10*3/2=16

  Was this answer useful?  Yes

Java 6:
Vector = 10
Arraylist = 10
Hashtable = 11
Hashmap = 16
Hashset = 16
Java 7:
Vector = 10
Arraylist = 0. Size will change to 10 once we add the element in the list
Hashtable = 11
Hashmap = 0. Size will change to 16 once we add the element in the map
Hashset = 0. Size will change to 16 once we add the element in the set

  Was this answer useful?  Yes

megesh

  • Jan 23rd, 2017
 

Vector class increment by 10 & ArrayList increment by [capacity=capacity*3/2]

  Was this answer useful?  Yes

Vivek Ranjan Singh

  • Apr 24th, 2017
 

Mitesh the calculation part of your solution is not right, kindly check it. Also you are using wrong formula to solve the growable size of the ArrayList.
Thanks

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Answer Question

Click here to Login / Register your free account


 
Send   Reset

 

Related Answered Questions

 

Related Open Questions