+import java.util.ArrayDeque;
+import java.util.NoSuchElementException;
class Main {
stackStrDeq.push("Hi");
stackStrDeq.push("Hugh");
- System.out.println("Stack index " + stackStrDeq.size());
- System.out.println("Stack head value " + stackStrDeq.pop());
- System.out.println("Stack index " + stackStrDeq.size());
- System.out.println("Stack head value " + stackStrDeq.pop());
- System.out.println("Stack index " + stackStrDeq.size());
- System.out.println("Stack head value " + stackStrDeq.pop());
- System.out.println("Stack index " + stackStrDeq.size());
- System.out.println("Stack head value " + stackStrDeq.pop());
- System.out.println("Stack index " + stackStrDeq.size());
- System.out.println("Stack head value " + stackStrDeq.pop());
- System.out.println("Stack index " + stackStrDeq.size());
- System.out.println("Stack head value " + stackStrDeq.pop());
- System.out.println("Stack index " + stackStrDeq.size());
-
+ try {
+ System.out.println("Stack index " + stackStrDeq.size());
+ System.out.println("Stack head value " + stackStrDeq.pop());
+ System.out.println("Stack index " + stackStrDeq.size());
+ System.out.println("Stack head value " + stackStrDeq.pop());
+ System.out.println("Stack index " + stackStrDeq.size());
+ System.out.println("Stack head value " + stackStrDeq.pop());
+ System.out.println("Stack index " + stackStrDeq.size());
+ System.out.println("Stack head value " + stackStrDeq.pop());
+ System.out.println("Stack index " + stackStrDeq.size());
+ System.out.println("Stack head value " + stackStrDeq.pop());
+ System.out.println("Stack index " + stackStrDeq.size());
+ // It will trigger the exception
+ System.out.println("Stack head value " + stackStrDeq.pop());
+ System.out.println("Stack index " + stackStrDeq.size());
+ }
+ catch (NoSuchElementException e) {
+ e.printStackTrace();
+ }
}
}