title: Determine Palindrome by Comparing Stack and Queue
body: <p>So for my assignment I have to write a program that uses instances of StackArrayBased.java and QueueArrayBased.java and sends a string to both of them and compares the dequeue() and pop() method returns to determine if the string is a palindrome. I have written the program but it is not returning the correct boolean, please help.</p>
  
  <pre><code>public class IsPalindrome{
      public static void main(String[]args){
          String str = new String("abcba");
          String str2 = new String("abcde");
          System.out.println(isPal(str));
          System.out.println(isPal(str2));
      }
      public static boolean isPal(String str)
      {
          StackArrayBased stack = new StackArrayBased();
          QueueArrayBased queue = new QueueArrayBased();
  
          String s = new String();
          for (int i = 0; i &lt; str.length( ); i++) {
              s = "" + str.charAt(i);
              System.out.println(s);
              queue.enqueue(s);
              stack.push(s);
          }
          // start to compare
          while (!queue.isEmpty( )) {
              if (queue.dequeue( ) != stack.pop( ))
                  return false;
          }
          // finished w/ empty queue (and empty stack)
          return true;
      }
  }
  </code></pre>