How to extract ArrayList using for loop?

These lines of code shows how to extract ArrayList using for loop.There are lots of method to extract ArrayList but here we are using for loop to get the elements of ArrayList.


								
package com.mindclues;

import java.util.ArrayList;
import java.util.List;

public class ArrayListExample {

    public static void main(String[] args) {
        
        List alist = new ArrayList();

        alist.add("1");
        alist.add("2");
        alist.add("3");
        alist.add("4");
        alist.add("5");

        String str = null;

        for (int index = 0; index < alist.size(); index++) {
            
            str = (String) alist.get(index);
            
            System.out.println(str);
        }

    }

}

							

								
1
2
3
4
5
							

Related Articles

post a comment