title: What is a "good" way to trigger function(s) of connecting "chambers" (Java)
body: <p>I've got the following problem I need to solve:</p>
  
  <p>Pretend you have a raster/grid of 5x5 filled with a's and b's:</p>
  
  <pre><code>a a a b a 
  a b a a a 
  a a a a a 
  b b b b b 
  a a b a a 
  </code></pre>
  
  <p>When I trigger (click) one of these "chambers" I would like to change the value of that chamber and all connecting chambers containing the same value (horizontally and vertically).</p>
  
  <p>Let's say I want to change the values to y.</p>
  
  <p>When I trigger (click) the "a" on position [2][1] (third position second row) I want the raster/grid to look like this:</p>
  
  <pre><code>y y y b y 
  y b y y y 
  y y y y y 
  b b b b b 
  a a b a a 
  </code></pre>
  
  <p>Notice the a's on the bottom. They should not have been changed (they did not connect).</p>
  
  <p>What is the best way to handle this?
  Is using a multidimensional array good enough? Or should I use a hashmap/arraylist? Does every "chamber" need to contain references to the connecting chambers?</p>
  
  <p>What would be a "beautiful", performant way to do this?</p>