Its known that Java ArrayList is implemented using arrays and initializes with capacity of 10 and increases its size by 50% . How to get the current ArrayList capacity not the Size of the ArrayList.
Thx
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I don’t think this is possible. What is your use case? I believe C# ArrayLists have a
.capacityproperty, but the Java ArrayList class doesn’t expose this information.You have the constructor that takes an initial capacity argument, and you have the
ensureCapacity()method which you could use to reduce the amount of incremental reallocation.You also have the
trimToSize()method you can use if you are really worried about memory usage.