11:11 pm - Sunday July 15, 2018

Stack 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
*@descriptions : This program explain the function and use of
ensureCapacity(int minCapacity)
*/

import java.io.*;
import java.util.*;
public class StackEnsureCapacity
{
public static void main(String arg[])throws Exception
{
Stack s=new Stack(); //to create object for Stack class
s.add(50); //to add an element in Stack
s.add("green"); //to add an element in Stack
s.add("red"); //to add an element in Stack
System.out.println(s);
System.out.println("Capacity of the stack is: " + s.capacity());
s.ensureCapacity(20); //increases the capacity of this stack
System.out.println("New Capacity of the stack is:" +s.capacity());
}
}

OUTPUT:

[50, green, red]
Capacity of the stack is:10
New Capacity of the stack is:20

BACK

Filed in: Z-A All Java Codes

Comments are closed.