title: What is wrong with my java method code? - Stacks
body: <p>I have spent the last few hours creating a method that will take null elements from stack s1, and place them into s2. The class should then print the stacks. The method is as follows</p>
  
  <pre><code>import net.datastructures.ArrayStack;
  import net.datastructures.Stack;
  import javax.imageio.IIOException;
  
  public class Stacks {
      public static &lt;E&gt; void compress(Stack&lt;E&gt; s1, Stack&lt;E&gt; s2) {
          int counter = 0;
          while (!s1.isEmpty()) {
              s1.peek();
              if (s1.peek() == null) {
                  s1.pop();        
              } else if (s1.peek() == !null) {
                  s1.pop();
                  s2.push();
                  counter++;
              }
              for (counter=10;counter&gt;s1.size(); counter--){
              }
              s2.pop();
              s1.push();
          }    
      }
  
      public static void main(String[] args) {
          // test method compress
          Stack&lt;Integer&gt; S1 = new ArrayStack&lt;Integer&gt;(10);
          S1.push(2);
          S1.push(null);
          S1.push(null);
          S1.push(4);
          S1.push(6);
          S1.push(null);
          Stack&lt;Integer&gt; s2 = new ArrayStack&lt;Integer&gt;(10);
          s2.push(7);
          s2.push(9);
          System.out.println("stack S1: " + S1);
          // prints: "stack S: [2, null, null, 4, 6, null]"
          System.out.println("stack s2: " + s2);
          // prints: "stack X: [7, 9]"
          compress(S1, s2);
          System.out.println("stack S1: " + S1);
          // should print: "stack S: [2, 4, 6]"
          System.out.println("stack s2: " + s2);
          // should print: "stack X: [7, 9]"
      }
  }
  </code></pre>
  
  <p>Eclipse is giving me errors for both peek() and push() methods; it allows the pop() method. It was my understanding that these methods are inherited? Any help is much appreciated!</p>