Skip to content
| Marketplace
Sign in
Visual Studio Code>Snippets>javaguru010New to Visual Studio Code? Get it now.
javaguru010

javaguru010

peace010

| (0) | Free
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

1️⃣ Question (Restated) Write a Java program to: Create a List that stores items of type String Use a for-each loop to print all items from the list

import java.util.*;

public class ListExample { public static void main(String[] args) {

    // Step 1: Create a List of String
    List<String> items = new ArrayList<>();

    // Step 2: Add items to the list
    items.add("Apple");
    items.add("Banana");
    items.add("Mango");
    items.add("Orange");

    // Step 3: Print items using for-each loop
    for (String item : items) {
        System.out.println(item);
    }
}

}

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft