title: Groups of continuous integers in a list in Kotlin
body: <p>I have a list of integers placed in order. What I want is to get groups of consecutive integers from the list.</p>
  
  <p>For example:</p>
  
  <p>Input: [19, 20, 21, 22, 23, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 59, 60, 61, 62, 63, 64, 65, 66, 73, 74, 75, 76, 77]</p>
  
  <p>Desired Output: [[19, 20, 21, 22, 23], [30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44], [59, 60, 61, 62, 63, 64, 65, 66], [73, 74, 75, 76, 77]]</p>
  
  <p>Here is my code:</p>
  
  <pre><code>    private fun getConsecutiveNumbers(srcList: ArrayList&lt;Int&gt;): List&lt;List&lt;Int&gt;&gt; {
  
          val listConsecNums = ArrayList&lt;List&lt;Int&gt;&gt;()
          var subList = ArrayList&lt;Int&gt;()
  
          for (i in 0 until srcList.size) {
              subList.add(srcList[i])
  
              if ((i + 1 &gt;= srcList.size) || (srcList[i] + 1 != srcList[i + 1])) {
                  listConsecNums.add(subList)
                  subList = ArrayList()
              }
          }
  
          return listConsecNums
  
      }
  
  
  </code></pre>
  
  <p>Here, the code assumes that the numbers are consecutive and collects them in a list until a non-consecutive number is found.</p>
  
  <p>This code works in the general case for what I want, but I was just wondering if there is a more efficient Kolin-y way to do the same.</p>
  
  <p>Any suggestions would be greatly appreciated.</p>