728x90 AdSpace

Latest Article



ArrayList Example Code In Java | How to add or get through Loop




ArrayList Example Code In Java  How to add or get through Loop   Java Examples  Java Program Sample How to loop ArrayList in Java How to use an ArrayList in Java with Source code


import java.util.ArrayList;

public class ArrayListExample {
    public static void main(String[] args) {
       
        ArrayList<Integer> al = new ArrayList<>();
        // Add element in ArrayList
        al.add(100);
        al.add(2);
        al.add(27);
        al.add(467);
        // Add element in specific index in ArrayList
        al.add(1, 3);
        // Print ArrayList
        for(int i=0 ;i< al.size();i++)
            System.out.println(al.get(i));
                   
        System.out.println("ArrayList Size is "+  al.size());
       
        // Remove element in ArrayList with specific index
        al.remove(2);
       
        System.out.println("ArrayList Size is "+  al.size());
       
        // Print ArrayList
        for(int i=0 ;i< al.size();i++)
            System.out.println(al.get(i));

    }
}


no image
  • Title : ArrayList Example Code In Java | How to add or get through Loop
  • Posted by :
  • Date : 12:18
  • Labels :






  • Blogger Comments
  • Facebook Comments

0 comments:

Post a Comment