Iterate Through All Elements In An ArrayList | Java Programs

Output:

*** Iterate All Elements In ArrayList ***

Iterating...

Orange
Apple
Banana
Pomegranate
Mango

Click Here For Java Online Compiler

Solution:

/**
 *
 * @author Alee Ahmed Kolachi
 */
import java.util.*;

public class IterateElementsArrayList {

    public static void main(String[] args) {
        // Creae a list and add some strings to the list
        List<String> arrayList = new ArrayList<String>();
        System.out.println("*** Iterate All Elements In ArrayList ***" + "\n");
        System.out.println("Iterating...");
        System.out.println();
        arrayList.add("Orange");
        arrayList.add("Apple");
        arrayList.add("Banana");
        arrayList.add("Pomegranate");
        arrayList.add("Mango");
        // Print the list
        for (String s : arrayList) {
            System.out.println(s);
        }
    }
}
Share This :

Related Post



sentiment_satisfied Emoticon