title: Find groups of 3 consecutive numbers or more in Java ArrayList
body: <p>I know there are similar questions out there and I've tried really hard to implement them but I can't quite seem to make them work for my needs. I don't need to find <strong>just</strong> consecutive numbers. I need to find consecutive numbers of 3 or more and replace the middle numbers with a hyphen.</p>
  
  <p>For example :</p>
  
  <ul>
  <li>arraylist contains <code>1,3,4,6,7,8,9</code>. The output should be <code>1,3,4,6-9</code>.</li>
  <li>or say the arraylist contains <code>1,3,4,5,7,8,9</code>. The output should be <code>1,3-5,7-9</code>.</li>
  </ul>
  
  <p>The problem I'm having is writing the logic to differentiate between 1 digit, 2 digits, 3 or more digits, and groups of consecutive digits that are 3 or more. Thanks in advance for whatever help you can provide! :-)</p>