The code demonstrates the usage of a foreach loop to iterate over the elements of a stack in Java. Let's go through the code step by step:
import java.io.*; import java.util.*; public class Foreach_Loop { public static void main(String[] args) { Stack < Integer > stack_list = new Stack < Integer > (); stack_list.push(10); stack_list.push(20); stack_list.push(30); stack_list.push(40); stack_list.push(50); stack_list.push(60); stack_list.push(70); stack_list.push(80); stack_list.push(90); stack_list.push(100); System.out.println("Stack Items : "); for (int val: stack_list) { System.out.println(val); } } }
Stack Items : 10 20 30 40 50 60 70 80 90 100
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions