
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What does the method ensureCapacity(int, minCapacity) do in java?
The ensureCapacity(int minCapacity) method of the class java.util.ArrayList 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.
Example
import java.util.ArrayList; public class ArrayListDemo { public static void main(String args[]) { ArrayList<Integer> arrlist = new ArrayList<Integer>(5); arrlist.add(10); arrlist.add(50); arrlist.add(30); arrlist.ensureCapacity(15); for (Integer number : arrlist) { System.out.println("Number = " + number); } } }
Output
Number = 10 Number = 50 Number = 30
- Related Questions & Answers
- What does the method fill(int[], int val) do in java?
- What does the method int capacity() do in java?
- What does the method get(int) do in java?
- What does the method remove(int) do in java?
- What does the method removeRange(int fromIndex, int toIndex) do in java?
- What does the method equals(int[] a1, int[] a2) do in java?
- What does the method copyOf(int[] original, int newLength) do in java?
- What does the method fill(int[], int fromIndex, int toIndex, int val) do in java?
- What does the method sort(int[] a, int fromIndex, int toIndex) do in java?
- What does the method copyOfRange(int[] original, int from, int to) do in java?
- What does the method hashCode(int[] a) do in java?
- What does the method sort(int[] a) do in java?
- What does the method elementAt(int index) do in java?
- What does the method removeElementAt(int index) do in java?
- What does the method fill(obj[], int fromIndex, int toIndex, int val) do in java?
Advertisements