7:02 am - Monday November 19, 2018

Stack Example Program for trimToSize()

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 trimToSize()
*/
import java.io.*;
import java.util.*;
public class StackTrim
{
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(60); //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.trimToSize(); //Trims the capacity of this stack to be the stack's current size
System.out.println("Capacity of the stack after trimming is: " + s.capacity());
System.out.println(s);
}
}

OUTPUT:
[50, 60, red]

Capacity of the stack is:10
Capacity of the stack after trimming is:3
[50, 60, red]

BACK

Filed in: Z-A All Java Codes

Comments are closed.