Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package collection;
- import java.util.Stack;
- public class StackImplementation {
- public static void main(String[] args) {
- Stack<String> stringStack = new Stack<>();
- stringStack.push("Kamrul"); //Adding string by push
- stringStack.push("Mou");
- stringStack.push("Emon");
- System.out.println("Initially: "+stringStack);
- int searchPosition = stringStack.search("Kamrul"); //Searching specific String.Returned Position number
- System.out.println("Searching... "+searchPosition);
- stringStack.pop(); //Removing element
- System.out.println("After removing top: "+stringStack);
- String peek = stringStack.peek(); //Removing upper elements without last one
- System.out.println("After peeking "+peek);
- boolean empty = stringStack.empty();
- System.out.println("Is Stack empty?: "+empty);
- }
- }
Advertisement
RAW Paste Data
Copied
Advertisement