The code demonstrates how to check if a stack is empty or not in Java using the empty method of the Stack class. Let's break down the code:
import java.io.*; import java.util.*; public class Chek_EmptyNot { public static void main(String[] args) { Stack stck_list = new Stack(); Stack stck_list2 = new Stack(); stck_list.push("Red"); stck_list.push("Pink"); stck_list.push("Yellow"); stck_list.push("Blue"); if (stck_list2.empty()) { System.out.println("Stack List 2 is Empty"); } else { System.out.println("Stack List 2 is Not Empty"); } if (stck_list.empty()) { System.out.println("Stack List 1 is Empty."); } else { System.out.println("Stack List 1 is Not Empty."); } } }
Stack List 2 is Empty Stack List 1 is Not Empty.
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions