title: Remove consecutive duplicate values in an Array - Arduino/ Java
body: <p>Im using Ardunio but happy for solutions in Java as this may help me understand.</p>
  
  <p>I have an array <code>stateX[]</code> of length 50 and it will hold values similar to:</p>
  
  <pre><code>0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, -1, -1, 0, 1, 1......
  </code></pre>
  
  <p>I'd like to know how I can remove the duplicate values from the array, which are <strong>next</strong> to each other. So the output would become a smaller array with elements:</p>
  
  <pre><code>0, 1, 0, -1, 0, 1
  </code></pre>
  
  <p>Obviously this smaller array will alter in size, so I'm unsure about that. And also how to detect the repeated values.</p>
  
  <p>Help appreciated, thanks</p>