simple application using arraylist methods
// simple application using arraylist methods
package collection;
import java.util.ArrayList;
public class UseArrayListMethods {
public static void main(String[] args)
{
ArrayList a1=new ArrayList();
System.out.println("Initial size of al:"+a1.size());
a1.add("J");
a1.add("A");
a1.add("V");
a1.add("A");
a1.add("P");
a1.add("O");
a1.add("I");
a1.add("N");
a1.add("T");
System.out.println("size After additions:"+a1.size());
System.out.println("Contents of al:"+a1);
a1.remove("J");
a1.remove(2);
a1.trimToSize();
System.out.println("size After deletions:"+a1.size());
System.out.println("contants of a1:"+a1);
a1.add(0,"J");
a1.add(3,"A");
System.out.println("size After additions:"+a1.size());
System.out.println("Contents of al:"+a1);
Object ia[]=a1.toArray();
String str="";
for(int i=0;i<ia.length;i++)
str+=ia[i];
System.out.println(str);
}
}
output:
Initial size of al:0
size After additions:9
Contents of al:[J, A, V, A, P, O, I, N, T]
size After deletions:7
contants of a1:[A, V, P, O, I, N, T]
size After additions:9
Contents of al:[J, A, V, A, P, O, I, N, T]
JAVAPOINT
0 comments:
Post a Comment