title: how to swap stacks element in java
body: <p>I want to do a swap to the two tops element in a stack 
  I tried, but can not figure it out </p>
  
  <pre><code>public void swap(){
  
   T temp=stack[topIndex];
   stack[topIndex]=stack[stack.length-1];
   stack[stack.length-1]=temp;
  
  
   }
  </code></pre>
  
  <p>topindex is already defined in superclass</p>