Array list and its method's demo

 package com.company;

import java.util.ArrayList;
public class CWH_91_ArrayList {
public static void main(String[] args) {
ArrayList<Integer> l1= new ArrayList<>();
ArrayList<Integer> l2= new ArrayList<>(50);
l2.add(12);
l2.add(14);
l2.add(16);
l2.add(10);
l2.add(19);
l2.add(34);
//l2.trimToSize();
//l2.add(54);
l1.add(4);
l1.add(1);
l1.add(2);
l1.add(12);
l1.add(9);
l1.add(0,5);
l1.add(0,56);
// l1.addAll(l2);
l1.set(0,45);
// l1.removeRange(1,4);
// l1.remove(6);
// l1.clear(); // clear method
// System.out.println( l1.clone()); //--> clone method
// System.out.println( l1.contains(7)); //--> contains method
// l1.ensureCapacity(500);
// System.out.println( l1.toArray());
// System.out.println( l1.retainAll(l2));
// System.out.println(l1.indexOf(12));
//// System.out.println(l1.lastIndexOf(12));
// for(int i =0; i< l1.size();i++){
// System.out.print(l1.get(i)+" ");
// }
// System.out.println(" ");
System.out.println(l1.size());
// for(int e: l1){ ---> second method
// System.out.println(e);
// }

}
}

Comments