BACK
The java.util.ArrayList.ensureCapacity(int minCapacity) method increases the capacity of this ArrayList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.
Related Articles
Example Program
import java.util.ArrayList; public class EnsureCapacity { public static void main(String[] args) { ArrayList<String> al = new ArrayList<String>(); al.add("10"); al.add("30"); al.add("60"); al.add("70"); al.add("80"); al.add("90"); al.add("10"); al.add("20"); al.add("100"); al.ensureCapacity(8); for (String number : al) { System.out.println("numbers are" + number); } } }
Output
numbers are 10
numbers are 30
numbers are 60
numbers are 70
numbers are 80
numbers are 90
numbers are 10
numbers are 20
numbers are 100
Description
The java.util.ArrayList.ensureCapacity(int minCapacity) method increases the capacity of this ArrayList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.
Declaration
Following is the declaration for java.util.ArrayList.ensureCapacity() method
public void ensureCapacity(int minCapacity)
Parameters
minCapacity — This is the desired minimum capacity
Return Value
This method does not return any value.
Exception
NA
BACK
Related Posts:
- Java Program used to ensure the minimum capacity of…
- AddAll program is to insert all elements in the specified…
- ArrayList example programs and Tutorial in java
- Java Program is used for memory optimization. It trims the…
- Contains object program to check whether the cbject exist in
This post first appeared on Core Java,Servlet,Jsp,Struts,Hibernate,Spring Fram, please read the originial post: here