title: How to remove certain items from a Stack
body: <p>I have a homework problem in which I need to remove all the green items from the stack. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>import java.util.*;
  import java.io.*;
  
  public class Pex
  {
  public static void main(String[] args)
  {
  Stack stack1 = new Stack(); 
  
  addPez(stack1);
  removeGreen(stack1);
  System.out.println(printStack(stack2));
  }
  
  public void addPez(Stack stack1)
  {
      stack1.push("yellow");
      stack1.push("red");
      stack1.push("green");
      stack1.push("green");
      stack1.push("yellow");
      stack1.push("yellow");
      stack1.push("red");
      stack1.push("green");
  }
  
  public static void removeGreen(Stack stack1)
  {
  Stack temp = new Stack();
  while (!stack1.isEmpty()){
    String check = (String)(stack1.pop());
      if(check.equals("green")){
      stack1.pop();}
      else{
      temp.push(check);}
  }
  Stack stack2 = new Stack();
  while (!temp.isEmpty()){
    String tmp = stack1.pop();
    stack2.push(tmp);}
  }
  
  public static void printStack(Stack stack2)
  {
  Stack xerox = stack2.clone();
  while (!xerox.isEmpty()){
    System.out.println(xerox.pop());}
  }
  }
  </code></pre>
  
  <p>Can someone point me in the right direction? I think I'm almost there.</p>
  
  <p>I also need to figure out why I am getting some errors. </p>
  
  <p>Here are the errors:</p>
  
  <pre><code>Pex.java:10: non-static method addPez(Stack) cannot be referenced from a static context
  addPez(stack1);
  ^
  Pex.java:12: cannot find symbol
  symbol  : variable stack2
  location: class Pex
  System.out.println(printStack(stack2));
                                ^
  
  Pex.java:39: incompatible types
  found   : java.lang.Object
  required: java.lang.String
    String tmp = stack1.pop();
                           ^
  
  Pex.java:45: incompatible types
  found   : java.lang.Object
  required: Stack
  Stack xerox = stack2.clone();
                            ^
  
  ./Stack.java:69: cannot find symbol
  symbol  : variable stack1
  location: class Stack
      stack2 = (Stack)(stack1.clone());
                       ^
  
  5 errors
  </code></pre>