How to print ArrayList using for loop in Java

1 Answer

0 votes
import java.util.*;
 
public class MyClass {
    public static void main(String args[]) {
        ArrayList<String> al = new ArrayList<String>();
         
        al.add("java");
        al.add("c");
        al.add("c++");
        al.add("python");
        al.add("php");
        al.add("nodejs");

        for (int i = 0; i < al.size() ; i++) {
            System.out.println(al.get(i));
        }
    }
}
 
 
/*run:
 
java
c
c++
python
php
nodejs

*/

 



answered Apr 28, 2020 by avibootz
edited Apr 28, 2020 by avibootz

Related questions

1 answer 327 views
1 answer 292 views
1 answer 192 views
192 views asked Mar 15, 2023 by avibootz
1 answer 249 views
1 answer 259 views
1 answer 260 views
260 views asked Apr 28, 2020 by avibootz
1 answer 236 views
236 views asked Sep 29, 2019 by avibootz
...