2:19 am - Tuesday November 13, 2018

ArrayList Example Program for ensureCapacity(int minCapacity)

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044
/**
@Author:candidjava.com
@Description:Increasing the array list capacity
 */
import java.util.*;

public class Capacity {
	public static void main(String args[]) {
		ArrayList<Integer> al = new ArrayList<Integer>(); // creating array list
															// object variable
		al.add(10);
		al.add(20);
		al.add(30);
		al.ensureCapacity(10); // incresing the arraylist capacity to 10
		System.out.println("Array List elements:");
		for (Integer no : al)
			// iterate throw arraylist
			System.out.println(no); // displaying the arraylist elements
	}
}

OUTPUT:

Array List elements:
10
20
30

Filed in: Z-A All Java Codes

Comments are closed.