Pages

Monday, August 18, 2025

Size of ArrayList in Java

import java.util.ArrayList;

public class Classroom {

    public static void main(String[] args) {
       ArrayList<Integer> list = new ArrayList<>();
       list.add(1);
       list.add(2);
       list.add(3);
       list.add(4);
       list.add(5);

       System.out.println(list.size());

       // print the arraylist
       for(int i=0; i<list.size(); i++) {
        System.out.print(list.get(i) + " ");
       }
    }
}

No comments:

Post a Comment

how to become red on codeforces by Errichto Algorithms | explained simply in a blog

 Yes. I found an available transcript of the video and summarized it simply. The video is “How To Become Red Coder? (codeforces.com)” by Err...