title: How to remove a particular element from a stack?
body: <p>I'm trying to accept an input of the element to be removed and pop all those from the stack.</p>
  
  <pre><code>String[] colors={"Red","Green","White","Yellow","Blue"};
  Scanner sc=new Scanner(System.in);
  Stack&lt;String&gt; stack=new Stack&lt;String&gt;();
  
  void push(){
          System.out.println("Stack after all the elements are pushed is");
  
          for(int i=0; i&lt;12; ++i){
              //defining a random element to be pushed into the stack
              int rnd=new Random().nextInt(colors.length);
              //pushing the element into the stack
              stack.push(colors[rnd]);
              if(i&gt;11)
                  break;
              //displaying all the elements present in the stack. 
              System.out.println(stack.get(i));
          }
  
  }
  
  void pop(String str){
      System.out.println("Enter the Color to be removed");
  
      while(!stack.empty()) {
  
          System.out.println("Element removed is "+stack.pop());
  
      }   
  
  
  }
  </code></pre>
  
  <p>main program</p>
  
  <pre><code>public static void main(String[] args) throws StackOverflowError {
      StackExample obj=new StackExample();
      obj.push();
      obj.display();
  
      Scanner sc= new Scanner(System.in);
      String s= sc.next();
      obj.pop(s);
      obj.display();
  }
  </code></pre>