title: Using Map in Java. How to not overwrite Value?
body: <pre><code>    for(int i = 0; i &lt; Board.NUM_OF_ROWS; i++) {
          for(int j = 0; j &lt; Board.NUM_OF_COLS; j++) {
              if(piece.canMove(board, piece.getX(), piece.getY(), i, j)) {
                  mappedPosition.put(i, j);
              }
          }
      }
  </code></pre>
  
  <p>In this code, I am trying to add a pair of (x,y) coordinate of a movable Position of a chess "piece". </p>
  
  <p>For example, I was expecting it to add [2,2], [2,4], [3,1], [3,5], [5,1], [5,5], [6,2], [6,4]</p>
  
  <p>But when I use put, it overwrites the Value when it has the same Key. So [2,2] just becomes [2,4] eventually. </p>
  
  <p>How can I get the full list of the pair without overwriting it?</p>