Sunday, February 25, 2018

Java program : Collections

import java.util.*;

class Collection_ArrayList_2
{  
    public static void main(String[] args)
    {
     ArrayList al =new ArrayList();
     al.add("Ashutosh");
     al.add(123);
     al.add("kumar");
     al.add(143);
     System.out.println(al);
     System.out.println(al.size());
     al.add(1,"Singh");
     System.out.println(al);
     System.out.println(al.size());
      al.remove(0);                  // using index
     System.out.println(al);
     System.out.println(al.size());
     //al.remove(10);
     Integer i=new Integer(143);      //ANOTHER WAY TO REMOVE A INTEGER DATA
     al.remove(i);
     System.out.println(al);
     System.out.println(al.size());
     al.remove("kumar");               //using specific object
     System.out.println(al);
     System.out.println(al.contains("ashutosh"));
     System.out.println(al.isEmpty());
     al.clear();
     System.out.println(al.isEmpty());
     }
   
}

Thanks
Happy programming!

No comments:

Post a Comment

Henry's law constant for CO 2 ​ in water is 1.67×10 ∘ Pa at 298 K . Calculate the quantity of CO 2 ​ in 500 mL , of soda water when packed under 2.5 atm CO 2 ​ pressure at 298 K .

  Explanation To calculate the amount of CO 2 ​ dissolved, we use Henry's Law: P = k H ​ × x _ C O 2 ​ where:\ P = partial pressure of...