Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Check capacity in Java

import java.util.ArrayList;
public class Demo {
	public static void main(String[] a) {
		ArrayList<Integer>arrList = new ArrayList<Integer>(5);
		arrList.add(100);
		arrList.add(200);
		arrList.add(300);
		arrList.add(400);
		arrList.add(500);
		arrList.add(600);
		arrList.add(700);
		System.out.println("Size of list = "+arrList.size());
		arrList.ensureCapacity(15);
		for (Integer number: arrList) {
			System.out.println(number);
		}
		arrList.add(100);
		arrList.add(200);
		arrList.add(300);
		arrList.add(400);
		arrList.add(500);
		System.out.println("Updated list...");
		System.out.println("Size of list = "+arrList.size());
		arrList.ensureCapacity(15);
		for (Integer number: arrList) {
			System.out.println(number);
		}
	}
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.