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 218 views
1 answer 207 views
1 answer 125 views
125 views asked Mar 15, 2023 by avibootz
1 answer 151 views
1 answer 175 views
1 answer 178 views
178 views asked Apr 28, 2020 by avibootz
1 answer 155 views
155 views asked Sep 29, 2019 by avibootz
...