What does ensureCapacity do in Java if you leave the parent

What does ensureCapacity () do in Java if you leave the parentheses empty. I know how to use it when you specify a capacity inside, but what happens if you don\'t?

Solution

ensureCapacity() is a method that ensures the minimum capacity to store elements in an array list. It is a method with an integer parameter minimum capacity. If the parentheses are empty, that means no values are passed. Not passing parameters for a function that accepts parameters will throw a compilation error.

javac arrlist.java

arrlist.java:15: error: method ensureCapacity in class ArrayList<E> cannot be applied to given types;

   arrlist.ensureCapacity();

^

required: int

found: no arguments

reason: actual and formal argument lists differ in length

where E is a type-variable:

E extends Object declared in class ArrayList

1 error


What does ensureCapacity () do in Java if you leave the parentheses empty. I know how to use it when you specify a capacity inside, but what happens if you don\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site