title: Java character comparison not working as intended
body: <p>So I am moving around a 2 dimensional array of characters. Depending on what the character at some coordinates is I may or may not want to add an object to an array list. 'R' is a legal movement 'X' is an illegal movement.</p>
  
  <p>The following piece of code checks to see if it is within the bounds of the grid and then checks for legal movements before creating objects and adding them to my array. The if statements are like this because they need to be opened in a particular order.</p>
  
  <pre><code> private static void OpenNodes()
   {
       if(currentNode.GetX() &gt; 0 &amp;&amp; currentNode.GetY() &gt; 0 &amp;&amp; currentNode.GetX() &lt; rowsCols &amp;&amp; currentNode.GetY() &lt; rowsCols)
       {//check R
           if(CheckAccessibility(currentNode.GetX() + 1, currentNode.GetY()))
           {
               CreateNode(currentNode.GetX() + 1, currentNode.GetY(), 2, "R");
           }
           //check RD
           if(CheckAccessibility(currentNode.GetX() + 1, currentNode.GetY() + 1))
           {
               CreateNode(currentNode.GetX() + 1, currentNode.GetY() + 1, 2, "RD");
           }
           //check D
           if(CheckAccessibility(currentNode.GetX(), currentNode.GetY() + 1))
           {
               CreateNode(currentNode.GetX(), currentNode.GetY() + 1, 2, "D");
           }
           //check DL
           if(CheckAccessibility(currentNode.GetX() - 1, currentNode.GetY() + 1))
           {
               CreateNode(currentNode.GetX() - 1, currentNode.GetY() + 1, 2, "DL");
           }
           //check L
           if(CheckAccessibility(currentNode.GetX() - 1, currentNode.GetY()))
           {
               CreateNode(currentNode.GetX() - 1, currentNode.GetY(), 2, "L");
           }
           //check UL
           if(CheckAccessibility(currentNode.GetX() - 1, currentNode.GetY() - 1))
           {
               CreateNode(currentNode.GetX() - 1, currentNode.GetY() - 1, 2, "UL");
           }
           //check U
           if(CheckAccessibility(currentNode.GetX(), currentNode.GetY() - 1))
           {
               CreateNode(currentNode.GetX(), currentNode.GetY() - 1, 2, "U");
           }
           //check UR
           if(CheckAccessibility(currentNode.GetX() + 1, currentNode.GetY() - 1))
           {
               CreateNode(currentNode.GetX() + 1, currentNode.GetY() - 1, 2, "UR");
           }
       }
   }
  </code></pre>
  
  <p>When I run CheckAccessibility like this:</p>
  
  <pre><code>     private static boolean CheckAccessibility(int varX, int varY)
   {
       if(grid[varX][varY] == 'X')
       {
           //return false;
       }
       return true;
   }
  </code></pre>
  
  <p>It returns exactly what I expect</p>
  
  <pre><code>x :2 y: 1 movement: R type: X
  x :2 y: 2 movement: RD type: X
  x :1 y: 2 movement: D type: R
  x :0 y: 2 movement: DL type: X
  x :0 y: 1 movement: L type: R
  x :0 y: 0 movement: UL type: R
  x :1 y: 0 movement: U type: R
  x :2 y: 0 movement: UR type: R
  </code></pre>
  
  <p>But When I run it properly</p>
  
  <pre><code>     private static boolean CheckAccessibility(int varX, int varY)
   {
       if(grid[varX][varY] == 'X')
       {
           return false;
       }
       return true;
   }
  </code></pre>
  
  <p>I get this:</p>
  
  <pre><code>x :2 y: 1 movement: R type: X
  x :0 y: 2 movement: DL type: X
  x :0 y: 1 movement: L type: R
  x :0 y: 0 movement: UL type: R
  x :1 y: 0 movement: U type: R
  </code></pre>
  
  <p>My grid looks like this</p>
  
  <pre><code>RRRXG
  RSXXR
  XRXXR
  XRRRR
  RRRRX
  </code></pre>
  
  <p>Can someone explain why this is failing to properly identify characters, causing it to create X nodes and remove R nodes?</p>
  
  <p>EDIT</p>
  
  <p>My create node function looks like this. (It is a bit less neat)</p>
  
  <pre><code>     private static boolean CreateNode(int xCoordinate, int yCoordinate, int varCost, String movementDirection)
   {   
      boolean visited = false;
  
       if(closed.size() &gt; 0)//check to see if we have ever previously been to this node
       {
           for(int i = 0; i &lt; closed.size(); i++)
           {
               if(closed.get(i).GetX() == xCoordinate &amp;&amp; closed.get(i).GetY() == yCoordinate)
               {
                   visited = true;
               }
           }
       }
  
       if(!visited)
       {
          if(algorithmType == 1) // if A* check to see if we are reopening a node already opened and if it is cheaper to visit this node from this new path
          {
              Node node = new Node(xCoordinate, yCoordinate, varCost, pathCost, grid[yCoordinate][xCoordinate], FindHeuristic(yCoordinate, xCoordinate), movementDirection);
  
              for(int i = 0; i &lt; open.size(); i++)
              {
                  if(open.get(i).GetX() == xCoordinate &amp;&amp; open.get(i).GetY() == yCoordinate)
                  {
                      if(node.GetF() &lt; open.get(i).GetF())//if the new path is cheaper remove old node and add new one
                      {
                          open.remove(i);
                      }
                      if(node.GetF() &gt;= open.get(i).GetF())//if new path is more expensive then do not add a node
                      {
                          return false;
                      }
                  }
              }
  
              open.add(node);
          }
          else
          {
              Node node = new Node(xCoordinate, yCoordinate, varCost, pathCost, grid[yCoordinate][xCoordinate], FindHeuristic(yCoordinate, xCoordinate), movementDirection);
              open.add(node);
          }
       }
       return true;
   }
  </code></pre>