1:06 pm - Tuesday September 25, 2018

ArrayList 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: Candid.com
*@Description: ArrayList Example Program For trimToSize and Contains
*/

import java.util.*;

public class ArrLst
{
public static void main(String[] args)
{
ArrayList arl = new ArrayList();

arl.add("A");
arl.add("X");
arl.add("K");
arl.add("H");
arl.add("O");

Iterator it = arl.iterator();
while(it.hasNext())
{
System.out.println(it.next());
}

arl.trimToSize();
System.out.println("Trims The Capacity Of ArrayList.......");
System.out.println("Array List Size : " + arl.size());

System.out.println("ArrayList contains K " + arl.contains("K"));
System.out.println("ArrayList contains B " + arl.contains("B"));
}
}

Output:

D:\venkatesh>javac ArrLst.java
D:\venkatesh>java ArrLst
A
X
K
H
O
Trims The Capacity Of ArrayList…….
Array List Size : 5
ArrayList contains K true
ArrayList contains B false

D:\venkatesh>

Filed in: Z-A All Java Codes

Comments are closed.